Wk 2: Background in Python and Unix Flashcards
Python tool for debugging online
pythontutor.com
What is dynamic typing of variables?
you don’t have to declare type of variable
Why does python allow for dynamic typing?
Everything in python is an object
What happens when you assign a different type to a variable that’s already been created?
Python creates a new object, and then points your variable at the new one (garbage collector takes care of original)
IS operator
tests if two variables point to the same object
assign a value to a variable
X = 5, X = “hello”, X = 4.5
Some string methods in python
capitalize(), lower() – return copies of the original (but don’t modify the original)
How to call lower() method on variable x?
x.lower()
How to assign output of x.lower to x?
x = x.lower()
Loop syntax example in python
for i in range (0,10): print (i)
Range(x,y) - x is inclusive? y is inclusive?
x is inclusive, y is exclusive
loop syntax increment by 2
for i in range (0,10,2): print (i)
while loop equivalent of “for i in range (0,10,2)”
i = 0; while i < 12: print(i); i+=3
Print var1 if var1 == 2
if var1 == 2:
print(var1)
If / else if / else syntax
if x==2; elif x==3: else: