Symbol Review Flashcards
(31 cards)
and
Logical and
e.g., True and False == False
as
Part of the with-as statement
assert
Assert (ensure) that something is true; if assertion is false, the program gives an assertion error
e.g., assert False, “Error!”
break
Stop this loop right now; move to next line of code
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; it does not process remaining code, but it iterates again
e.g., while True: continue
def
Define a function
e.g., def X(): pass
del
Delete from dictionary
Del X[Y]
elif
Else if Condition
else
Else Condition
except
If an exception happens, do this except ValueError, print(e)
exec
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
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
Importing specific parts of a module
e.g., from X import Y
global
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
if
If Condition
import
import a module into this one 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
or
Logical or
pass
This block is empty
e.g.,
def empty():
pass # a function that does nothing (yet)