Learn Python the Hard Way Symbol Review – Flashcards
Unlock all answers in this set
Unlock answersquestion
and
answer
Called Logical AND operator. If both the operands are true then then condition becomes true. ex. (a and b) is true.
question
del
answer
The del statement is a way to remove an item from a list given its index instead of its value: the del statement. ex. a = [-1, 1, 66.25, 333, 333, 1234.5] del a[0] a [1, 66.25, 333, 333, 1234.5]
question
from
answer
The root of a from-import statement. The from-import statement is used to import specific objects from a module. ex. from x import y
question
not
answer
A negation for the defined operation. ex. not(2 == 1)
question
while
answer
The while loop continues until the expression becomes false. The expression has to be a logical expression and must return either a true or a false value. ex. while (x < 10):
question
as
answer
Used in a 'with' statement to define the alias to assign each result of with x to. ex. with open("x.log") as x
question
elif
answer
A conditional execution statement following an 'if'. Shorthand for an else-if. ex. if x==0: do stuff elif x==1: do more stuff
question
global
answer
The global statement is a declaration which holds for the entire current code block. It means that the listed identifiers are to be interpreted as globals. ex. globes = 0 def glob_1(): global globes globes = 1 def glob_2(): print globes glob_1() glob_2()
question
or
answer
Boolean operator to accept if either condition is True, return True. ex. if (1==1 or 1==2):
question
with
answer
The with statement is used to wrap the execution of a block with functionality provided by a separate guard object (see context-managers). This allows common try-except-finally usage patterns to be encapsulated for convenient reuse. ex. with open("bzr.log") as x: data = x.read() print data
question
assert
answer
The assert statement verifies that the expression defined resolves to true. If it does not it will raise an AssertionError with an optional expression2. ex. assert (x==1 or x==2)
question
else
answer
When all conditional execution statements in an If, Elif block return false, the else will catch and execute. ex. if x==1: do1 elif x==2: do2 else: do3
question
if
answer
A conditional execution statement which executes some code if a statement is True. ex. if you == x: print "whew!"
question
pass
answer
A null operation. When this is executed nothing happens. ex. if x<0: derp() else pass
question
yield
answer
Return a generator object(like a list or tuple) instead of a static object. ex. def direct(path): yield os.path.walk(path)
question
break
answer
Will exit out of the 'nearest' loop. ex. while x<10: if x<0: break print x x = x+1
question
except
answer
When a try statement fails the except catches the failure and returns. ex. while True: try: num = raw_input(int()) break except: print "Thats not an int."
question
import
answer
The import statement initializes an external module so its functions can be used in the current environment. ex. import os print os.path("c:")
question
print
answer
The print statement will export the argument to STDOUT. ex. print "sup"
question
class
answer
A object that contains functions and can be instantiated. ex. class Man: def height(self): print "TALL DUDE"
question
exec
answer
Allows for the dynamic execution of Python code. ex. test = print "Sup" exec(test)
question
in
answer
When used with an if, allows the code to loop through all members of a generator object. ex. x = 1 if x in [1,2,3,4,5]: print "Sup"
question
raise
answer
Used to call an exception that can be customized per situation. ex. raise Exception, "PC LOAD LETTER"
question
continue
answer
When encountered, causes the application to skip the rest of the current loop. ex. k = [1,2,3,4,5] for x in k: if x>3: print "TOO BEEG" continue print x
question
finally
answer
The finally statement is the cleanup function in a 'try' statement. While all of the try...except...else are executed, if an exception is raised it is parsed and printed in the finally statement. This also causes any application that is preemptively interrupted to still execute the finally statement before closing out of the loop. ex. try: d = file("herp.txt") while True: line = d.readline() if len(line) == 0: break time.sleep(2) print line, finally: d.close() print "Cleaning up your mess."
question
is
answer
Compares the object identity of two objects. Two objects referencing the same memory location will return True, but objects that are 'equal' will not. ex. 1 == 1 1 is 1 [] == [] [] is []
question
return
answer
Outputs the value returned by a function. This cannot be a generator object as return will only return that it is a generator function. ex. def x return 2 * 2
question
def
answer
Define a function. ex. def testfunc(x)
question
for
answer
Iterate through a generator object. The for specifically defines a variable to store each individual iteration as the generator counts through. ex. i = ["Hello","world!"] for x in i: print x
question
lambda
answer
Creates an anonymous function that is not bound to a specific namespace. ex. for i in (1,2,3,4,5): a = lambda x: x * x print a(i)
question
True
answer
Boolean true
question
False
answer
Boolean
question
None
answer
Null
question
strings
answer
A string is a sequence characters which mathematical functions cannot be performed on.
question
numbers
answer
Numbers are a sequence of numbers that math can be performed on.
question
floats
answer
A float is a string of numbers that is equal to 32-bit storage of integers and fraction representing decimal places.
question
lists
answer
A list is a dynamic storage of multiple variables in a single object that can be iterated. Unlike a tuple, lists can be changed after creation.
question
'
answer
single quote
question
"
answer
double quote
question
a
answer
ASCII bell
question
b
answer
ASCII backspace
question
f
answer
ASCII formfeed
question
n
answer
newline
question
r
answer
carriage return
question
t
answer
tab
question
v
answer
vertical tab
question
%d
answer
signed decimal
question
%l
answer
signed decimal (same as %d)
question
%u
answer
Signed decimal (obsolete)
question
%o
answer
octal
question
%x
answer
signed hex, lowercase
question
%X
answer
signed hex, uppercase
question
%e
answer
floating point in exponential format, lowercase
question
%E
answer
floating oint in exponential format, uppercase
question
%f
answer
floating point decimal format
question
%F
answer
floating point decimal format
question
%g
answer
floating point format. Lowercase exponential format if less than -4, decimal format otherwise
question
%G
answer
floating point format. Uppercase exponential format if less than -4, decimal format otherwise
question
%r
answer
String, converts using repr(), "x"
question
%s
answer
string, converts using str(), x
question
%%
answer
No argument converted. Results in '%' in the result
question
+
answer
add
question
-
answer
subtract
question
*
answer
multiply
question
**
answer
Exponentiation, 'to the power of'
question
/
answer
divide
question
//
answer
quotient, division without any remainder
question
%
answer
remainder
question
<
answer
less than
question
>
answer
greater than
question
<=
answer
less than or equal
question
>=
answer
greater than or equal
question
==
answer
comparison
question
!=
answer
not equal to comparison
question
()
answer
tuple
question
[]
answer
list
question
{}
answer
set
question
@
answer
at (decorators)
question
=
answer
declaration of variable
question
+=
answer
add to the variable by argument and re-declare as the new value
question
-=
answer
subtract from the variable by the argument and re-declare as the new value
question
/=
answer
divide by the variable by the argument and redeclare as the new value
question
*=
answer
multiply the variable by the argument and re-declare as the new value
question
//=
answer
get the quotient of the variable by the argument and re-declare as the new value
question
%=
answer
Get the remainder by dividing the variable by the argument and re-declaring it as the new value
question
**=
answer
exponentiate the variable by the argument and re-declare as the new value