Wk 2: Background in Python and Unix Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Python tool for debugging online

A

pythontutor.com

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is dynamic typing of variables?

A

you don’t have to declare type of variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why does python allow for dynamic typing?

A

Everything in python is an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when you assign a different type to a variable that’s already been created?

A

Python creates a new object, and then points your variable at the new one (garbage collector takes care of original)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

IS operator

A

tests if two variables point to the same object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

assign a value to a variable

A

X = 5, X = “hello”, X = 4.5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Some string methods in python

A

capitalize(), lower() – return copies of the original (but don’t modify the original)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to call lower() method on variable x?

A

x.lower()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to assign output of x.lower to x?

A

x = x.lower()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Loop syntax example in python

A

for i in range (0,10): print (i)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Range(x,y) - x is inclusive? y is inclusive?

A

x is inclusive, y is exclusive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

loop syntax increment by 2

A

for i in range (0,10,2): print (i)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

while loop equivalent of “for i in range (0,10,2)”

A

i = 0; while i < 12: print(i); i+=3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Print var1 if var1 == 2

A

if var1 == 2:

print(var1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

If / else if / else syntax

A

if x==2; elif x==3: else:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

define a function

A

def func_name(args): xxxx; return val

17
Q

what’s the downside of not having to define the type of the args or the return value

A

will get the error at run time if a value is passed that isn’t the expected type

18
Q

what does a function return if there is not return statement

A

returns None

19
Q

What’s the scope of a variable set at the top of the code

A

Global - it’s available throughout all code, and the functions

20
Q

What’s the scope of a variable set inside of a function

A

only available in that function, unless it has the same name as a prev set global var