Python Flashcards

1
Q

declare function in P

A
def «name»(«_param1», _...):
    _return «_return value»
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

declare a block equivalent in P

A
def absolute_value(num):
    if num >= 0:
        return num
    else:
        return -num

» use indentation

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

if else statement in P

A
if «condition1»:
    «action1»
_elif «condition2»:
    «action2»
_else:
    «default action»
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

import in P

A

import «library/object» as «alias»

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

comment in P

A

«comment»

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

write to console in P

A

print(«object»)

print(«object1», «_object2», _…)

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

check if script is entry point in P

A

if __name__ == “__main__”:

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

template/f-strings in P

A

f”«string» { «value» } «string»”

before:
“«string» %s «string» %s” % («value1», «value2»)
“«string» {} «string» {}”.format(«value1», «value2»)

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

name variables and functions in P

A

sample_variable_name

» lowercase
» with underscores

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

package manager in P

A

pip / pip3

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