Symbol Review Flashcards
and
Logical and. (e.g. True and False == False)
as
Part of the with-as statement. (e.g. with X as Y: pass)
assert
Assert (ensure) that something is true. (e.g. assert False, “Error!”)
break
Stop this loop right now. (e.g. while True: break)
class
Define a class. (e.g. class Person(object))
continue
Don’t process more of the loop, do it again. (e.g. while True: continue)
def
Define a function. (e.g. def X(): pass)
del
Delete from dictionary. (e.g. del X[Y])
elif
Else if condition. (e.g. if: X; elif: Y; else: J)
else
Else condition. (e.g. if: X; elif: Y; else: J)
except
If an exception happens, do this. (e.g. except ValueError, e: print(e))
exec
Run a string as Python. (e.g. exec ‘print(“hello”)’)
finally
Exceptions or not, finally do this no matter what. (e.g. finally: pass)
for
Loop over a collection of things. (e.g. for X in Y: pass)
from
Import specific parts of a module. (e.g. from x import Y)
global
Declare that you want a global variable. (e.g. global X)
if
If condition. (e.g. if: X; elif: Y; else: J)
import
Import a module to use. (e.g. import os)
in
Part of for-loops. Also a test of X in Y. (e.g. for X in Y: pass, 1 in [1] == True)
is
Like == to test equality (e.g. 1 is 1 == True)
lambda
Create a short anonymous function. (e.g. s = lambda y: y ** y; s(3)
not
Logical not. (e.g. not True == False)
or
Logical or. (e.g. True or False == True)
pass
This block is empty. (e.g. def empty(): pass)
Print this string. (e.g. print(‘this string’))
raise
Raise an exception when things go wrong. (e.g. raise ValueError(“No”)
return
Exit the function with a return value. (e.g. def X(): return Y)
try
Try this block, and if exception, go to except. (e.g. try: pass)