











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information on various resources for python programming, including consultants, workshops, piazza forum, and office hours. It also covers the basics of python, such as data types (int, float, bool, str), operator precedence, and variables. Exercises for understanding assignment statements.
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












§ Daily office hours (see website) with consultants § Very useful when working on assignments
§ Runs parallel to this class – completely optional § See website; talk to advisors in Olin 167.
§ Go here first before sending question in e-mail
§ Available in Thurston 102 between lectures
add, then multiply multiply, then add
§ Create a new variable name and give it a value x = 5
§ Tells the computer to DO something (not give a value) § Typing it into >>> gets no response (but it is working)
§ These expressions can even have variables in them x = x + 2 the value the variable the expression the variable x 5 Two steps to execute an assignment:
x 5 7 A: I did it correctly! B: I drew another box named x C: I did something else D: I did nothing—just watched
A: I did it correctly! B: I drew another box called “interestRate” C: I stored the value in the box for x D: I thought it would use int division E: I did something else (or nothing)
§ Variables can hold values of any type § Variables can hold different types at different times § Use type(x) to find out the type of the value in x § Use names of types for conversion, comparison
x = 1 x = x / 2.
§ Each variable restricted to values of just one type ç x contains an int value ç x now contains a float value type(x) == int x = float(x) type(x) == float
§ 'abc d' (Python prefers) § "abc d" (most languages)
§ Delineate with “other quote” § Example : " ' " or ' " ' § What if need both " and '?
§ Format: \ + letter § Special or invisible chars Char Meaning ' single quote " double quote \n new line \t tab \ backslash Type : str
§ s[0] is 'a' § s[4] is 'd' § s[5] causes an error § s[0:2] is 'ab' (excludes c) § s[2:] is 'c d'
a b c d
H e l l o
a
l
l
A: 'lo a' B: 'lo' C: 'lo ' D: 'o ' E: I do not know
§ s[0] is 'a' § s[4] is 'd' § s[5] causes an error § s[0:2] is 'ab' (excludes c) § s[2:] is 'c d'
a b c d
H e l l o
a
l
l
A: 'o all' B: 'Hello' C: 'Hell' D: Error! E: I do not know
s = 'abracadabra' 'a' in s == True 'cad' in s == True 'foo' in s == False s.index('a') == 0 s.index('rac') == 2 s.count('a') == 5 len(s) == 11 s.strip('a') == ‘bracadabr’ ' cs1110 '.strip() == 'cs1110' s 1 in s 2 asks whether s 1 is a substring of s 2. Result is type bool. s 1 .index( s 2 ) returns the index of the first occurrence of s 2 in s 1. s 1 .count( s 2 ) returns the number of occurrences of s 2 in s 1. len( s ) returns the number of characters in s. s 1 .strip( s 2 ) returns a copy of s 1 with characters in s 2 removed from the ends. Just s 1 .strip() defaults to removing white space from the ends. More (too much!) information in Python documentation on www.python.org (see Library Reference, built-in types)