CIS192: Python Programming

Similar documents
CIS192 Python Programming. Robert Rand. August 27, 2015

LECTURE 1. Getting Started with Python

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

Advanced Algorithms and Computational Models (module A)

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

CS1 Lecture 3 Jan. 18, 2019

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Basic Python 3 Programming (Theory & Practical)

Python Programming, bridging course 2011

CS1 Lecture 3 Jan. 22, 2018

61A Lecture 3. Friday, September 5

Lecture 1. Basic Ruby 1 / 61

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi

Python Class-Lesson1 Instructor: Yao

A Brief Introduction to Python for those who know Java. (Last extensive revision: Daniel Moroz, fall 2015)

And Parallelism. Parallelism in Prolog. OR Parallelism

ENGR 102 Engineering Lab I - Computation

Outline. Simple types in Python Collections Processing collections Strings Tips. 1 On Python language. 2 How to use Python. 3 Syntax of Python

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

Welcome to CS61A! Last modified: Thu Jan 23 03:58: CS61A: Lecture #1 1

Full file at

Lecture 2: Variables & Assignments

Information Science 1

CS 3030 Scripting Languages Syllabus

CME 193: Introduction to Scientific Python Lecture 1: Introduction

Accelerating Information Technology Innovation

Lecture 1. Course Overview, Python Basics

CS 3030 Scripting Languages Syllabus

SOFT 161. Class Meeting 1.6


CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points

Announcements. 1. Forms to return today after class:

Lecture 1. Course Overview Types & Expressions

CIS 110: Introduction to Computer Programming

Course Introduction and Python Basics

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

egrapher Language Reference Manual

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

Full file at

QUIZ: What value is stored in a after this

A Brief Introduction to Python for those who know Java Last extensive revision: Jie Gao, Fall 2018 Previous revisions: Daniel Moroz, Fall 2015

Babu Madhav Institute of Information Technology, UTU 2015

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Beyond Blocks: Python Session #1

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

CS 2316 Individual Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 18th, before 11:55 PM Out of 100 points

Introduction to Python

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Python I. Some material adapted from Upenn cmpe391 slides and other sources

CS 3813/718 Fall Python Programming. Professor Liang Huang.

Lecture 1. Course Overview, Python Basics

CS/ENGRD 2110 FALL 2018

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary

Some material adapted from Upenn cmpe391 slides and other sources

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Data Handing in Python

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

CGS 3066: Spring 2015 JavaScript Reference

Senthil Kumaran S

Information Science 1

CIS 194: Homework 3. Due Wednesday, February 11, Interpreters. Meet SImPL

The current topic: Python. Announcements. Python. Python

Introduction to: Computers & Programming: Review prior to 1 st Midterm

CS 241 Data Organization. August 21, 2018

Python Basics. Lecture and Lab 5 Day Course. Python Basics

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

Fundamentals of Programming (Python) Getting Started with Programming

Introduction to Python

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

Flow Control: Branches and loops

CNG 140 C Programming. Syllabus. Course Info Fall Semester. Catalog Description

Introduction to Data Structures

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Introduction to programming with Python

Functions. Nate Foster Spring 2018

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2

Part III Appendices 165

CS 111X - Spring Final Exam - KEY

CS101: Intro to Computing Summer Week 1

The SPL Programming Language Reference Manual

CS 112: Intro to Comp Prog

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361)

Lecture 3. More About C

SD314 Outils pour le Big Data

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018

Advanced Python. Executive Summary, Session 1

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability

CSC148: Week 1

A Brief Introduction to Scheme (I)

Here n is a variable name. The value of that variable is 176.

CMPE012 Computer Engineering 12 (and Lab) Computing Systems and Assembly Language Programming. Summer 2009

Python 3000 and You. Guido van Rossum PyCon March 14, 2008

Transcription:

CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34

Outline 1 Logistics Rooms and Office Hours Grading Class Materials 2 Python What is Python? The Basics 3 Wrapping Up the First Class Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 2 / 34

What s CIS 192? CIS 19X courses 0.5 Credits each Designed to teach practical skills Intended to be lightweight and highly functional. CIS 192: Python Programming Powerful scripting language used in academia and industry Simple to read and write Take this class if You have some programming experience You are relatively new to Python Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 3 / 34

CIS 192 Logistics Class: CIS 192 Python Programming Listed as CIS 192 201 Room: Towne 309 Time: Wednesdays, 12:00-1:30pm Instructor: Harry Smith Undergrad Junior in Logic Call me Harry! (Not a professor!) TAs Alex Frias Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 4 / 34

CIS 192 001 Class: CIS 19X Shared Lecture Room: Towne 100 Time: Tuesdays, 6:00-7:30pm General, useful info: command line intro, Git, overview of the Internet, HTML/CSS (new this year!) Instructor: Joe Devietti (Listed as Swapneel Sheth) Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 5 / 34

Outline 1 Logistics Rooms and Office Hours Grading Class Materials 2 Python What is Python? The Basics 3 Wrapping Up the First Class Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 6 / 34

Grade Breakdown Homework: 70% 1 per week some time before the end of the semester Programming assignments These will range from collections of exercises on a week s material to mini-projects with time given to work in class with instructor assistance. Will be looking for a lot of feedback here throughout the semester. Final Project: 25% Anything you want Individually or in a pair Participation: 5% Attendance/Piazza/Office Hours Homework Info Drop one homework (lowest grade) Late homeworks accepted up to 24 hours late with 20% penalty. Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 7 / 34

Homeworks Python 3 (3.42 or latest stable) Submit on Canvas! Graded for correctness (80%) and style (20%) Due Sunday nights at 11:59pm HW1 due next Sunday Academic Integrity The Office of Student Conduct Don t copy-paste code from other people Don t have mid-level discussions High-Level: What are the pros/cons of using Python for X? Low-Level: What is the syntax for decorators? Mid-Level: How did you do HW 1? If you are going to do "research" for a problem... Do not copy and paste code from a StackOverflow response Do not look at or copy material that directly solves a question In the case of reasonable online research, you must absolutely cite sources. When in doubt, consult me or Alex. Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 8 / 34

Outline 1 Logistics Rooms and Office Hours Grading Class Materials 2 Python What is Python? The Basics 3 Wrapping Up the First Class Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 9 / 34

Reading No text book! Python Official Documentation In-class slides and code (available on CIS 192 website) Piazza Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 10 / 34

Programming Environment Unix system recommended Ubuntu Virtual Machine / Eniac Editor Can use anything you want (Sublime Text, Atom, vim, emacs, etc.) IDEs also available: PyDev for Eclipse, PyCharm Set your editor to interpret tabs as four spaces Python is whitespace-sensitive Limited support for students not using the above. Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 11 / 34

Outline 1 Logistics Rooms and Office Hours Grading Class Materials 2 Python What is Python? The Basics 3 Wrapping Up the First Class Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 12 / 34

Easy to Learn Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 13 / 34

Easy to Use Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 14 / 34

Easy to Abuse Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 15 / 34

History Designer: Guido van Rossum Benevolent Dictator For Life (BDFL) Multi-Paradigm: Object-Oriented, Functional, Imperative... Strongly and Dynamically Typed Whitespace delimited blocks Garbage Collected Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 16 / 34

Philosophy The Zen of Python Beautiful is better than ugly Explicit is better than implicit Simple is better than complex Complex is better than complicated Readability Counts Other ideas There should be one obvious way to do it Clarity over marginal efficiency We re all consenting adults here Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 17 / 34

Outline 1 Logistics Rooms and Office Hours Grading Class Materials 2 Python What is Python? The Basics 3 Wrapping Up the First Class Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 18 / 34

REPL Read Evaluate Print Loop (a.k.a. an interpreter) Type Python at the terminal Test out language behavior here Get information with dir(), help(), type() Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 19 / 34

Identifiers, Names, Variables All 3 mean the same thing Variable naming convention Functions and variables: lower_with_underscore my_num = 5 Constants: UPPER_WITH_UNDERSCORE SECONDS_PER_MINUTE = 60 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 20 / 34

Binding x = 1 y = x x = a X 1 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 21 / 34

Binding x = 1 y = x x = a X 1 Y Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 21 / 34

Binding x = 1 y = x x = a a X 1 Y Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 21 / 34

Objects Python treats all data as objects Identity Memory address Does not change Type Does not change Value Mutable: value can be changed (e.g. [1,2]) Immutable: value cannot be changed after creation (e.g. (1,2)) Equality Use is for referential equality (do x and y point to the same object?) Use == for structural equality (are x and y equal based on object s eq method?) Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 22 / 34

Types Every object has a type Inspect types with type(object) isinstance(object, type) checks type hierarchy Types can be compared for equality, but you usually want isinstance Some types: int, float str tuple, list, dict range, bool, None function Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 23 / 34

Math Literals Integers: 1, 2 Floats: 1.0, 2e10 Complex: 1j, 2e10j Binary: 0b1001, Hex: 0xFF, Octal: 0o72 Operations Arithmetic: + - * / Power: ** Integer division: // Modulus: % Bitwise: & ˆ Comparison: <, >, <=, >=, ==,!= Assignment Operators += *= /= &=... No ++ or -- Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 24 / 34

Booleans True and False Boolean operators: and or not Any object can be tested for truth value for use in conditionals, or as operands of the above Boolean operations. "Falsy" None 0 0.0 Any empty string/sequence/collection ([],(), etc.) Almost everything in Python is True. Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 25 / 34

Comparisons <, <=, >, >=, ==,!=, is, is not Chainable binary operators This means that x < y <= z and x < y and y <= z are equivalent. x is y simplifies to True when x and y refer to the same object. Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 26 / 34

Strings Can use either single or double quotes Use single to show double flip-flop " " and " " Triplequote for multiline string Can concat strings by separating string literals with whitespace All strings are unicode Prefixing with r means raw. No need to escape characters: r \n Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 27 / 34

Conditionals One if block Zero or more elif blocks Zero or one else block Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 28 / 34

Sequences Immutable Strings, Tuples Mutable Lists Operations len() Indexing Slicing in not in Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 29 / 34

Range Immutable sequence of numbers range(stop), range(start,stop[,step]) start defaults to 0 step defaults to 1 All numbers in [start,stop) by incrementing start by step Negative steps are valid Memory efficent: Calculates values as you iterate over them Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 30 / 34

Loops For each loops (for item in my_list:) Iterate over an object While loops (while some_condition:) Continues as long as condition holds Both else: executes after loop finishes For loops: the sequence has been exhausted While loops: the condition has been made False. break: stops the loop and skips the else clause continue: starts the next iteration of the loop Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 31 / 34

Functions Functions are first class They re objects, too! Can pass them as arguments Can assign them to variables Define functions with a def return keyword to return a value pass: Use this to finish a function that is empty so it compiles. If a function reaches the end of the block without returning, it will return None (null) Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 32 / 34

Importing Modules Allow use of other python files and libraries imports: import math Named imports: import math as m Specific imports: from math import pow Import all: from math import * Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 33 / 34

Last thoughts Confirm that you are on Canvas/Piazza Fill out the anonymous survey on Piazza/in your email If you are registered for the class and are preparing to drop, please come talk to me If you are not registered for the class, please come talk to me I have Office Hours immediately following this class in DRL 2W11 Homework 1 to be released shortly (or is already released) and will be due January 28. Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 34 / 34