python, Python Programming Review, Introduction to Computer
Programming: Python, Python Programming Test, Introduction to Python 3
Programming, Introduction to Programming in Python study guide with
Q&As
Data Type
String, Int, Float, Boolean
Class
Same as data type
How do you iterate through a list?
For Loop!
scores = [1,2,3,4]
for s in scores:
print(s)
Write a function named powers() that takes a positive integer n as input and prints, on the
screen, all the powers of 2 from 2^1 to 2^n.
def powers(n):
for i in range(1,n+1):
print(2**i)
How do you identify the length of a list?
len(list)
How do you iterate through a list by index instead of value?
range(len(list))
Iterate through list "pets" through the indexes
for i in range(len(pets)): #i is assigned 0, 1, 2...
print(pets[p]) #print object at index i
Why would you use range(len(list))?
,When you want to iterate through a list by index instead of value.
ie: list of strings
ie: when comparing values in a list.
-index i is followed by i+1
Python Data Types
- Integer
- Floating point
- Boolean
- String
- List
Algebraic Operators
+, -, , /, //, %, *
Algebraic Funtions
- abs()
- min()
- max()
Assignment Statement
x=4
Algebraic Expression
-3+7
-2*3+1
- 14//3
- 2**4
Boolean Expression
2<3
True
Comparison Operators
>, <, ==, >=, <=, !=
Boolean Operators
,- and
- or
- not
String Operators
- in
- not in
- s n, n s
-s+t
- s[i]
List Operators
- x in lst
- x not in lst
- lstA + lstB
- lst n, n lst
- lst[i]
List Functions
- len(lst)
- min(lst)
- max(lst)
- sum(lst)
List Methods
- lst.append(item)
- lst.count(item)
- lst.index(item)
- lst.insert(index, item)
- lst.pop()
- lst.remove(item)
- lst.reverse()
- lst.sort()
Constructors
- int()
- float()
, - str()
- list()
Implicit Type Conversion
>>> 3 + 0.35
3.35
Explicit Type Conversion
Attributes of a Variable
Name
Address
Type
Value
Scope
Lifetime
Language design binding
bounding a symbol to an operation
Language Implementation binding
type sizes vary from machine to machine but are bounded when the compiler is installed
Compile time binding
A variable is bound to a type when a program is compiled
Load time binding
When a program is loaded the addresses are bound to the variables
Link time binding
When a program links to a library the names of the variables and subprograms in the library are
bound
Static Type binding
Variable types does not change after the program compiles
Dynamic Type binding
Variable types are bounded during the runtime or can change during the runtime