Symbol Review Flashcards

(31 cards)

1
Q

and

A

Logical and

e.g., True and False == False

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

as

A

Part of the with-as statement

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

assert

A

Assert (ensure) that something is true; if assertion is false, the program gives an assertion error

e.g., assert False, “Error!”

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

break

A

Stop this loop right now; move to next line of code

e.g., while True: break

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

class

A

Define a class

e.g., class Person(object)

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

continue

A

Don’t process more of the loop, do it again; it does not process remaining code, but it iterates again

e.g., while True: continue

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

def

A

Define a function

e.g., def X(): pass

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

del

A

Delete from dictionary

Del X[Y]

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

elif

A

Else if Condition

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

else

A

Else Condition

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

except

A

If an exception happens, do this except ValueError, print(e)

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

exec

A

Run a string as Python

It can take three parameters:

object: As already said this can be a string or object code
globals: This can be a dictionary and the parameter is optional
locals: This can be a mapping object and is also optional

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

finally

A

Exceptions or not, finally do this no matter what

e.g., finally: pass

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

for

A

Loop over a collection of things

e.g., for X in Y: pass

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

from

A

Importing specific parts of a module

e.g., from X import Y

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

global

A

Declare that you want a global variable; allows to modify the variable outside of the current scope; creates a global variable and makes changes to the variable in a local context
A variable defined outside of a function is global by default

e.g., global X

17
Q

if

18
Q

import

A

import a module into this one to use

e.g. import os

19
Q

in

A

Part of for-loops. Also a test of X in Y

e.g., for X in Y: pass + 1 in [1] == True

20
Q

is

A

Like == to test equality

e.g. 1 is 1 == True

21
Q

lambda

A

Create a short anonymous function

e.g., s = lambda y:y**y; s(3)

22
Q

not

23
Q

or

24
Q

pass

A

This block is empty
e.g.,
def empty():
pass # a function that does nothing (yet)

25
print
Print this string
26
raise
Raise an exception when things go wrong If no expressions are present, "raise" re-raises the last expression that was raised in the current scope e.g., Raise ValueError("No")
27
return
Exit the function with a return value; it hands back a value to the caller ``` e.g., def X(): return ```
28
try
Try this block and if exception, go to except e.g., try: pass
29
while
While Loop
30
with
With an expression as a variable do With X as Y: pass
31
yield
Returns the caller a generator e.g., def X(): return Y X().next()