PYTHON PROGRAMMING. The History of Python. Features of Python. This Course

Similar documents
10/9/2012. Operator is an operation performed over data at runtime. Arithmetic, Logical, Comparison, Assignment, Etc. Operators have precedence

CSE 401 Midterm Exam 11/5/10 Sample Solution

Unit 5 Vocabulary. A function is a special relationship where each input has a single output.

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

Functor (1A) Young Won Lim 10/5/17

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

Stack. A list whose end points are pointed by top and bottom

Functor (1A) Young Won Lim 8/2/17

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

Fall 2017 Midterm Exam 1 October 19, You may not use any books, notes, or electronic devices during this exam.

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam.

box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:

1. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES)

L2-Python-Data-Structures

Questions About Numbers. Number Systems and Arithmetic. Introduction to Binary Numbers. Negative Numbers?

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples

CS201 Discussion 10 DRAWTREE + TRIES

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls

CS 430 Spring Mike Lam, Professor. Parsing

Agilent Mass Hunter Software

Introduction to Julia for Bioinformatics

EXPONENTIAL & POWER GRAPHS

12-B FRACTIONS AND DECIMALS

9.1 apply the distance and midpoint formulas

Fig.25: the Role of LEX

Midterm 2 Sample solution

Subtracting Fractions

2014 Haskell January Test Regular Expressions and Finite Automata

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

Lab 1 - Counter. Create a project. Add files to the project. Compile design files. Run simulation. Debug results

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Epson Projector Content Manager Operation Guide

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

MATLAB Session for CS4514

Dr. D.M. Akbar Hussain

Reducing a DFA to a Minimal DFA

Representation of Numbers. Number Representation. Representation of Numbers. 32-bit Unsigned Integers 3/24/2014. Fixed point Integer Representation

pdfapilot Server 2 Manual

UNIT 11. Query Optimization

MIPS I/O and Interrupt

COMP 423 lecture 11 Jan. 28, 2008

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

Essential Question What are some of the characteristics of the graph of a rational function?

Engineer To Engineer Note

CMPSC 470: Compiler Construction

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

From Dependencies to Evaluation Strategies

Data sharing in OpenMP

EECS 281: Homework #4 Due: Thursday, October 7, 2004

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

Definition of Regular Expression

Lexical Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

Lecture T4: Pattern Matching

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012

Fall 2018 Midterm 2 November 15, 2018

binary trees, expression trees

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

EasyMP Multi PC Projection Operation Guide

EasyMP Network Projection Operation Guide

Epson iprojection Operation Guide (Windows/Mac)

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays

10.5 Graphing Quadratic Functions

Small Business Networking

Deposit a Technical Report in PubRep

Pointers and Arrays. More Pointer Examples. Pointers CS 217

x )Scales are the reciprocal of each other. e

Integration. October 25, 2016

Reducing Costs with Duck Typing. Structural

Integration. September 28, 2017

9 4. CISC - Curriculum & Instruction Steering Committee. California County Superintendents Educational Services Association

Assignment 4. Due 09/18/17

Small Business Networking

Small Business Networking

Stained Glass Design. Teaching Goals:

COMMON HALF YEARLY EXAMINATION DECEMBER 2018

Assignment 11 (The Last One) Due Date for Programs: December 13, 2016

Slides for Data Mining by I. H. Witten and E. Frank

OUTPUT DELIVERY SYSTEM

cisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example:

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

5 Regular 4-Sided Composition

Lecture Overview. Knowledge-based systems in Bioinformatics, 1MB602. Procedural abstraction. The sum procedure. Integration as a procedure

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

ASTs, Regex, Parsing, and Pretty Printing

such that the S i cover S, or equivalently S

MATH 25 CLASS 5 NOTES, SEP

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

ECE 468/573 Midterm 1 September 28, 2012

4452 Mathematical Modeling Lecture 4: Lagrange Multipliers

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

Study Guide for Exam 3

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

Small Business Networking

Small Business Networking

Introduction To Files In Pascal

INDIAN COMMUNITY SCHOOL INFORMATICS PRACTICES 2012

Control-Flow Analysis and Loop Detection

Transcription:

The History of Python PYTHON PROGRAMMING Dr Christin Hill 7 9 November 2016 Invented by Guido vn Rossum* t the Centrum Wiskunde & Informtic in Amsterdm in the erly 1990s Nmed fter Monty Python s Flying Circus Grew in populrity throughout the 2000s, initilly s web-scripting lnguge Now used extensively in computing nd scientific circles, e.g. by Google, YouTube, CERN, NASA, Disney,... * Python s Benign Dicttor For Life (BDFL) Fetures of Python Free nd open-source Multi-pltform Interpreted High-level, expressive nd redble Object-oriented Dynmiclly-typed Strongly-typed Automtic memory-mngement 3 dys is short time! This Course The focus is on bredth, not depth The exercises ( prcticls ) re where most of the lerning hppens Some of the prcticls re tough: it isn t necessry to complete them ll...... but solutions will be provided It tkes long time to remember everything to do with progrmming lnguge; luckily, the Python documenttion is very good.

We cover: This Course The Python shell: using Python s clcultor The essentil syntx of Python progrm; loops, flow-control, functions, etc. Mjor dt structures: strings, lists, tuples, sets nd dictionries File I/O, Errors nd Exceptions, cool Python stuff Clsses nd object-oriented progrmming (briefly) Floting point rithmetic n introduction to NumPy, SciPy nd Mtplotlib Lerning Python C. Hill, Lerning Scientific Progrmming with Python, CUP (2016) M. Lutz, Lerning Python, 5th ed., O Reilly (2013) M. Pilgrim, Dive Into Python, APRESS (2004); lso vilble online for free t: http://www.diveintopython.net/ M. Dwson, Python Progrmming for the Absolute Beginner, 3rd ed., Course Technology PTR (2010) D. M. Bezley, Python Essentil Reference, Addison Wesley (2009) S. Oliveir nd D. Stewrt, Writing Scientific Softwre: A Guide to Good Style, CUP (2006) Online Python Resources The Python Shell The officil Python site: http://www.python.org/ The officil Python documenttion: http://docs.python.org/ The officil Python tutoril: http://docs.python.org/tutoril/ My own scipython website: http://scipython.com The mighty StckOverflow: http://stckoverflow.com/ (serch the rchive before posting your question!) Lern Python the hrd wy: http://lernpythonthehrdwy.org/ Lern Python the very hrd wy: http://www.pythonchllenge.com/ From terminl (e.g. tcsh on socrtes): % python Python 2.6.4 (r264:75706, Jul 20 2010, 05:25:12) [GCC 4.4.3] on sunos5 Type "help", "copyright", "credits" or "license" for more informtion. >>>

Jupyter Notebook Serch for Jupyter t the Windows Strt menu Lunches in browser menu Crete folder to store your work Select New Python Notebook to open new window with your new Jupyter Notebook cells. Shortcuts: Shift-Enter: Execute the cell, showing ny output, nd then move the cursor onto the cell below. If there is no cell below, new empty one will be creted. CTRL-Enter: Execute the cell in plce, but keep the cursor in the current cell. Useful for quick disposble commnds to check if commnd works or for retrieving directory listing. Alt-Enter: Execute the cell, showing ny output, nd then insert new cell immeditely beneth it. Bsic Arithmetic Bsic opertors: + (ddition) - (subtrction) * (multipliction) / (division) // (integer division) % (modulus, i.e. reminder) ** (exponentition) >>> 3 + 4 7 >>> 6 * 7 42 >>> 2**3 >>> 14 // 3 4 >>> 14 % 3 2 >>> 14. / 3 4.666666666666667 Bsic Arithmetic You cn use the Python shell s clcultor! Exmples: Integer division rounds down ( floor division ) Floting point numbers re indicted by deciml point The integer 3 is utomticlly converted up to flot >>> // n Bsic Arithmetic A reminder bout modulr rithmetic mens floor(/n)= -, the n lrgest integer less thn or equl to /n >>> b = % n is the reminder, b = - - n n For exmple, 7 // 3 = 2 since 7 = 2*3 + 1 7 % 3 = 1

Bsic Arithmetic Opertor Precedence Opertors with the sme precedence evlute left-to-right But n unprenthesised sequence of power opertors re evluted right-to-left (e.g. 3**2**3 = 3**, not 9**3) Use prentheses to over-ride precedence In decresing order of precendence: ** unry - (i.e. negtive numbers) *, /, //, % +, - Opertor Precedence Exmples: >>> 3 + 4 * 2 11 >>> (3 + 4) * 2 14 >>> -2**4-16 >>> (-2)**4 16 >>> 2 * 14 % 3 1 >>> 14 % 3 * 2 4 Bsic Arithmetic Exponentition hs higher precedence thn unry minus Use prentheses to rise -2 to the fourth power. Evlution is left-to-right, so this is 2 % 3...... but this is 2 * 2 >>> = >>> b = 17 >>> >>> - b -9 >>> / 4 + b 19 >>> c = b - 7 >>> c 10 Vribles Vribles re used store, lbel nd mnipulte dt They do not need to be declred before use b 17 b - 7 = 17-7 = 10 c >>> = >>> b = >>> = >>> b = >>> = 3.14 Vribles nmes b b references objects 3.14 Numbers, like nd 3.14 re immutble: the line = 3.14 cretes new object nd lbels it. Note tht b is not chnged.

>>> = >>> = * 1.2 >>> 9.6 Dynmic typing This is n ssignment: multiply by 1.2 nd store the result in, not mthemticl eqution. The multipliction chnges the type of from int to flot (it is utomticlly promoted to the more generl type needed to store the result) An exmple of duck typing: we don t need to declre the type of : if it looks like duck, nd it wlks like duck nd it qucks like duck, then it s duck A shorter wy of writing: >>> = * 1.2 is to use the idiom: >>> *= 1.2 Rules for vrible nmes Vrible Nmes Vribles re cse-sensitive ( nd A re different vribles) Cn contin ny letter, the underscore chrcter ( _ ), nd ny digit (0-9)...... but must not strt with digit Must not be reserved keyword. In Python 3: Flse ssert del for in or while brek elif from is pss with None clss else globl lmbd rise yield nd continue except if nonlocl return s def finlly import not try Style guide for vrible nmes Vrible Nmes Mke your vrible nmes meningful: re is better thn But not too long: the_re_of_the_tringle is too unwieldy Use lower-cse nmes, with words seprted by underscores: men_height not MenHeight ( CmelCse ) Don t use I (upper-cse i), l (lower cse L), or O (upper-cse o): they look too much like the digits 1 nd 0. The vribles i, j, k re usully expected to be integer counters Comprison opertors Objects (such s numbers) re compred using the opertors: ==!= > < >= <= (equls) (not equl to) (greter thn) (less thn) (greter thn or equl to) (less thn or equl to) The result of comprison is boolen object (of type bool): or Flse. For exmple, >>> 7 == Flse >>> 4 >= 3.14 Agin, 4 is promoted up to flot so the comprison is between objects of the sme type.

Logic The keywords nd, or nd not cn be used to string together comprisons. In decresing order of precedence: not nd or For exmple: >>> 7 > 4 nd -1 <= 0 >>> not 7.5 < 0.9 or 4 == 4 >>> not (7.5 < 0.9 or 4 == 4) Flse Over-ride precedence with prentheses Truth tbles: P T F not P F T P Q P nd Q T T T F T F T F F F F F P Q P or Q T T T F T T T F T F F F Logic or is inclusive