Learn Python The Hard Way Exercise 37 Symbol Review – Flashcards
Unlock all answers in this set
Unlock answersquestion
and (keyword)
answer
Logical and. >>> True and False == False
question
as (keyword)
answer
Part of the with-as statement. >>> with X as Y: pass
question
assert (keyword)
answer
Assert (ensure) that something is true. >>> assert False, "Error!"
question
break (keyword)
answer
Stop this loop right now. >>> while True: break
question
class (keyword)
answer
Define a class. >>> class Person(object)
question
continue (keyword)
answer
Don't process more of the loop, do it again. >>> while True: continue
question
def (keyword)
answer
Define a function. >>> def X(): pass
question
del (keyword)
answer
Delete from dictionary. >>> delX[Y]
question
elif (keyword)
answer
Else if condition. >>> if: X; elif: Y; else: J
question
else (keyword)
answer
Else condition >>> if: X; elif: Y; else: J
question
except (keyword)
answer
If an exception happens, do this. >>> except ValueError, e: print e
question
exec (keyword)
answer
Run a string as Python. >>> exec 'print "Hello"'
question
finally (keyword)
answer
Exceptions or not, finally do this no matter what. >>> finally: pass
question
for (keyword)
answer
Loop over a collection of things. >>> for X in Y: pass
question
from (keyword)
answer
Importing specific parts of a module. >>> import X from Y
question
global (keyword)
answer
Declare that you want a global variable. >>> global X
question
if (keyword)
answer
If condition. >>> if: X; elif: Y; else: J
question
import (keyword)
answer
Import a module into this one to use. >>> import os
question
in (keyword)
answer
Part of 'for-loops'. Also a test of X in Y. >>> for X in Y: pass >>> 1 in [1] == True
question
lambda (keyword)
answer
Create a short anonymous function. >>> s = lambda y: y ** y; s (3)
question
not (keyword)
answer
Logical not. >>> not True == False
question
or (keyword)
answer
Logical or. >>> True or False == True
question
pass (keyword)
answer
This block is empty. >>> def empty(): pass
question
print (keyword)
answer
Print this string. >>> print 'this string'
question
raise (keyword)
answer
Raise an exception when things go wrong. >>> raise ValueError("No")
question
return (keyword)
answer
Exit the function with a return value. >>> def X(): return Y
question
try (keyword)
answer
Try this block, and if exception, go to 'except'. >>> try: pass
question
while (keyword)
answer
While loop. >>> while X: pass
question
with (keyword)
answer
With an expression as a variable do. >>> with X as Y: pass
question
yield (keyword)
answer
Pause here and return to caller. >>> def X(): yield Y; X().next()
question
True (data type)
answer
True boolean value. >>> True or False == True
question
False (data type)
answer
False boolean value. >>> False and True == False
question
None (data type)
answer
Represents "nothing" or "no value". >>> x = None
question
strings (data type)
answer
Store textual information. >>> x = "hello"
question
numbers (data type)
answer
Stores integers. >>> i = 100
question
floats (data type)
answer
Stores decimals. >>> i = 10.389
question
lists (data type)
answer
Stores a list of things. >>> j = [1,2,3,4]
question
dicts (data type)
answer
Stores a key=value mapping of things. >>> e = {'x': 1, 'y': 2}
question
(string escape sequence)
answer
Backslash
question
' (string escape sequence)
answer
Single-quote
question
" (string escape sequence)
answer
Double-quote
question
a (string escape sequence)
answer
Bell
question
b (string escape sequence)
answer
Backspace
question
f (string escape sequence)
answer
Formfeed
question
n (string escape sequence)
answer
Newline
question
r (string escape sequence)
answer
Carriage
question
t (string escape sequence)
answer
Tab
question
v (string escape sequence)
answer
Vertical tab
question
%d (string format)
answer
Decimal integers (not floating point). >>> "%d" % 45 == '45'
question
%i (string format)
answer
Same as %d. >>> "%i" % 45 == '45'
question
%o (string format)
answer
Octal number. >>> "%o" % 1000 == '1750'
question
%u (string format)
answer
Unsigned decimal. >>> "%u" % -1000 == '-1000'
question
%x (string format)
answer
Hexadecimal lowercase. >>> "%x" % 1000 == '3e8'
question
%X (string format)
answer
Hexadecimal uppercase. >>> "%X" % 1000 == '3E8'
question
%e (string format)
answer
Exponential notation, lowercase 'e'. >>> "%e" % 1000 == '1.000000e+03'
question
%E (string format)
answer
Exponential notation, uppercase 'E'. >>> "%E" % 1000 == '1.000000E+03'
question
%f (string format)
answer
Floating point real number. >>> "%f" % 10.34 == '10.340000'
question
%F (string format)
answer
Same as %f. (Floating point real number.) >>> "%F" % 10.34 == '10.340000'
question
%g (string format)
answer
Either %f or %e, whichever is shorter. >>> "%g" % 10.34 == '10.34'
question
%G (string format)
answer
Same as %g but uppercase. (Either %f or %e, whichever is shorter.) >>> "%G" % 10.34 == '10.34'
question
%c (string format)
answer
Character format. >>> "%c" % 34 == '"'
question
%r (string format)
answer
Repr format (debugging format). >>> "%r" % int == ""
question
%s (string format)
answer
String format. >>> "%s there" % 'hi' == 'hi there'
question
%% (string format)
answer
A percent sign. "%g%%" % 10.34 == '10.34%'
question
+ (operator)
answer
Addition >>> 2 + 4 == 6
question
- (operator)
answer
Subtraction >>> 2 - 4 == -2
question
* (operator)
answer
Multiplication >>> 2 * 4 == 8
question
** (operator)
answer
Power of >>> 2 ** 4 == 16
question
/ (operator)
answer
Division >>> 2 / 4.0 == 0.5
question
// (operator)
answer
Floor division >>> 2 // 4.0 == 0.0
question
% (operator)
answer
String interpolate or modulus >>> 2 % 4 == 2
question
< (operator)
answer
Less than >>> 4 < 4 == False
question
> (operator)
answer
Greater than >>> 4 > 4 == False
question
<= (operator)
answer
Less than equal >>> 4 <= 4 == True
question
>= (operator)
answer
Greater than equal >>> 4>= 4 == True
question
== (operator)
answer
Equal >>> 4 == 5 == False
question
!= (operator)
answer
Not equal >>> 4 != 5 = True
question
(operator)
answer
Not equal >>> 4 5 == True
question
( ) (operator)
answer
Parenthesis >>> len('hi') == 2
question
[ ] (operator)
answer
List brackets >>> [1,3,4]
question
{ } (operator)
answer
Dict curly braces >>> {'x': 5, 'y': 10}
question
@ (operator)
answer
At (decorators) >>> @classmethod
question
, (operator)
answer
Comma >>> range(1, 10)
question
: (operator)
answer
Colon >>> def X():
question
. (operator)
answer
Dot >>> self.x = 10
question
= (operator)
answer
Assign equal >>> x = 10
question
; (operator)
answer
semi-colon >>> print "hi"; print "there"
question
+= (operator)
answer
Add and assign >>> x = 1; x += 2
question
-= (operator)
answer
Subtract and assign >>> x = 1; x -= 2
question
*= (operator)
answer
Multiply and assign >>> x = 1; x *= 2
question
/= (operator)
answer
Divide and assign >>> x = 1; x /= 2
question
//= (operator)
answer
Floor divide and assign >>> x = 1; x//= 2
question
%= (operator)
answer
Modulus assign >>> x = 1; x %= 2
question
**= (operator)
answer
Power assign >>> x = 1; x **= 2