Crash Dive into Python

Similar documents
Crash Dive into Python

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

Introduction to Python

Welcome to Introduction to programming in Python

A Python Tour: Just a Brief Introduction CS 303e: Elements of Computers and Programming

Exercise 1: Python Language Basics

Introduction to Python

2! Multimedia Programming with! Python and SDL

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control

Introduction to Python

Python Loops and String Manipulation

[1] Learned how to set up our computer for scripting with python et al. [3] Solved a simple data logistics problem using natural language/pseudocode.

Exercise 4 Learning Python language fundamentals

Install Java Development Kit (JDK) 1.8

Introduction to Computer Science I Spring 2014 Mid-term exam Solutions

Some programming experience in a high-level structured programming language is recommended.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

CS 106 Introduction to Computer Science I

CRASH COURSE PYTHON. Het begint met een idee

Python Programming: An Introduction To Computer Science

Python Basics. S.R. Doty. August 27, Preliminaries What is Python? Installation and documentation... 4

Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue?

COMS Programming Languages Python: Lecture 1. Kangkook Jee

Programming Languages CIS 443

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:

The programming language C. sws1 1

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

6.170 Tutorial 3 - Ruby Basics

0.5 Lab: Introduction to Python sets, lists, dictionaries, and comprehensions

Python Lists and Loops

CSC 221: Computer Programming I. Fall 2011

Computational Mathematics with Python

Outline. multiple choice quiz bottom-up design. the modules main program: quiz.py namespaces in Python

Computer Science 217

LEARNING TO PROGRAM WITH PYTHON. Richard L. Halterman

Python Evaluation Rules

Welcome to Introduction to Computers and Programming Course using Python

Introduction to Python for Text Analysis

Computational Mathematics with Python

PYTHON Basics

FEEG Applied Programming 5 - Tutorial Session

The C Programming Language course syllabus associate level

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

NLP Lab Session Week 3 Bigram Frequencies and Mutual Information Scores in NLTK September 16, 2015

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

The Smalltalk Programming Language. Beatrice Åkerblom

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Outline Basic concepts of Python language

Objects and classes. Objects and classes. Jarkko Toivonen (CS Department) Programming in Python 1

Android Based Appointment Scheduler and Location Helper using file operation

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn Claus Führer Simulation Tools Automn / 65

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

Python 2 and 3 compatibility testing via optional run-time type checking

Software Tool Seminar WS Taming the Snake

13 File Output and Input

Introduction to Programming Languages and Techniques. xkcd.com FULL PYTHON TUTORIAL

WAYNESBORO AREA SCHOOL DISTRICT CURRICULUM INTRODUCTION TO COMPUTER SCIENCE (June 2014)

Python Programming: An Introduction to Computer Science

Introduction to Python

Python Programming: An Introduction to Computer Science

PuLP: A Linear Programming Toolkit for Python

Computational Mathematics with Python

Scientific Programming with Python. Randy M. Wadkins, Ph.D. Asst. Prof. of Chemistry & Biochem.

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala

This module explains fundamental aspects of Microsoft Dynamics NAV Development Environment.

Computer Programming Tutorial

Introduction to Computer Science Using Python and Pygame

Python 3 Programming. OCR GCSE Computing

PL / SQL Basics. Chapter 3

Invitation to Ezhil : A Tamil Programming Language for Early Computer-Science Education 07/10/13

ios Application Development &

The VGIST Multi-Modal Data Management and Query System

Computer Science for San Francisco Youth

CPSC 121: Models of Computation Assignment #4, due Wednesday, July 22nd, 2009 at 14:00

Programming and Software Development CTAG Alignments

Introduction to Programming with Python Session 3 Notes

ML for the Working Programmer

Computer Programming I

ECE 341 Coding Standard

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Touchstone File Format Specification. Rev 2.0

Easy Script in Python ST10020a Rev

River Dell Regional School District. Computer Programming with Python Curriculum

Assignment 2: Option Pricing and the Black-Scholes formula The University of British Columbia Science One CS Instructor: Michael Gelbart

Pemrograman Dasar. Basic Elements Of Java

Computations in Number Theory Using Python: A Brief Introduction

Chapter 2 Writing Simple Programs

Introduction to. Marty Stepp University of Washington

Java Crash Course Part I

CS106A, Stanford Handout #38. Strings and Chars

Topic 11 Scanner object, conditional execution

Python Tutorial. Release Guido van Rossum Fred L. Drake, Jr., editor. June 18, Python Software Foundation

Beyond the Mouse A Short Course on Programming

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

Transcription:

ECPE 170 University of the Pacific Crash Dive into Python

2 Lab Schedule Ac:vi:es Assignments Due Today Lab 8 Python Due by Oct 26 th 5:00am Endianness Lab 9 Tuesday Due by Nov 2 nd 5:00am Network programming Lab 8 Network Programming

3 Person of the Day: Guido van Rossum ì Author of the Python programming language ì Self- appointed Benevolent Dictator For Life ì Chose the name because he was in a slightly irreverent mood (and a big fan of Monty Python's Flying Circus) ì Has worked in numerous organiza:ons, including NIST, Google and Dropbox Computer Systems and Networks Fall 2015

4 Python

5 What is Python? Interpreted language for scrip:ng and many other uses Features: Objects Dynamic types A rich set of libraries Extensibility through C (for speed cri:cal code) It is most notorious for its indenta:on rules, using whitespace or tabs (and it is very picky)

6 Python Datatypes Python supports many datatypes from C or C++: Integers, floats, strings, booleans Recent Python versions support other useful types: Complex numbers Sequences (tuples, lists) Dic:onaries Sets Bytes and bytearrays

7 Runtime evaluation Python is interpreted and has dynamic typing Implica:ons: Syntax is checked when code is first encountered Variable types (or even their existence) aren t checked un:l the code is executed Result: Code can execute correctly for a while un:l either an undefined variable is encountered, or it is used incorrectly (i.e., trying to access an integer as a sequence)

8 Python Tuples A tuple is an immutable collec:on of objects Tuples are denoted by parenthesis t = (1,2,3) The objects in a tuple do not need to be of the same type

9 Python Lists A list is an mutable collec:on of objects Lists are denoted by square brackets l = [1.5, a, (3,True)]

10 Python Sequences Tuples and lists are both types of sequences: individual items can be accessed in various ways To access a par:cular item in a sequence: t = (1,2,3) l = [1.5, a, (3,True)] print(t[0],l[1]) 1 a

11 Python Sequences Sequences can also be accessed from the end (instead of beginning) using nega9ve indices t = (1,2,3) l = [1.5, a, (3,True)] print(t[-2],l[-1]) 2 (3, True)

12 Python Sequences Slices (subsets of sequences) are accessed by using a : Note that the second index (if supplied) is one greater than actual last object in the slice t = (1,2,3) l = [1.5, a, (3,True)] print(t[0:2]) print(l[1:]) (1,2) ['a, (3, True)]

13 Python Dictionaries A dic9onary is an associa:ve array of keys and value pairs d={'a':1, 'b':2, 3:'c'} print(d) print(d.keys()) print(d.values()) print(d['a']) print(d['c']) {'a': 1, 3: 'c', 'b': 2} dict_keys(['a', 3, 'b']) dict_values([1, 'c', 2]) 1 KeyError: 'c

14 Python Error Handling Python handles errors using the try and except statements try: d['c'] except: print("key 'c' is not present") Key 'c' is not present

15 Python Blocks Python uses whitespace and : to denote blocks Note: tabs and spaces are not interchangeable! Within a block, all lines are indented exactly the same amount print(l) print(l) [1.5, 'a', (3, True)] IndentationError: unexpected indent

16 Python Statements and Flow Control Python supports these statements: if elif else for while if 1 > 2: print(a) elif 3 > 2: print(t) else: print("neither") (1, 2, 3)

17 Python Statements and Flow Control The for statement takes a sequence as its input This works for any sequence type Tuples, lists, strings, etc for x in (1,3,5,'a'): print(x) 1 3 5 a

18 Python Statements and Flow Control For the equivalent of a C for loop, use the range class for i in range(0,9,3): print(i) 0 3 6 This is equivalent to: for (int i=0; i < 9; i += 3)

19 Using Python Libraries Libraries (modules) are accessed using the import statement import math print(math.sin(2)) 0.9092974268256817