LPtHW – Exercise 37: Symbol Review – Flashcards
Unlock all answers in this set
Unlock answersquestion
and
answer
Called Boolean/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 it's index instead of it's 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 statemetn is used to import specific objects from a module. ex. from x import y
question
not
answer
Called Boolean/Logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true then Boolean/Logical NOT operator will make it false. ex. not(a and b) is false.
question
while
answer
Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. 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
Short for else if, used as a conditional execution statement following an 'if' statement. ex. if x==0: do this elif x==1: do this
question
global
answer
A declaration which holds for the entire code block. It means that the listed identifiers are to be interpreted as globals.
question
or
answer
Boolean/Logical operator. If either condition is True, return True.
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("foo.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.
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
Terminate loop.
question
except
answer
When a try statement fails, the except catches the failure and returns.
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.
question
class
answer
An object that contains functions and can be instantiated. Defines an object.
question
exec
answer
Allows for the dynamic execution of Python code. Execute code.
question
in
answer
When used with an if, allows the code to loop through all members of a generator object. Evaluates to true if x is a member of the set s. ex. x = 1 if x in [1,2,3,4,5]: print "winner"
question
raise
answer
Used to call an exception that can be customized per situation. ex. raise Exception, "PC LOAD LETTER"
question
continue
answer
Skip the rest of the current loop and continue loop cycle. ex. a = [1, 2, 3, 4, 5] for x in a: if x>3: print "too high!" 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("derp.txt") while True line = d.readline() if len(line)==0: break time.sleep(2) print line finally: d.close() print "Cleaning."
question
is
answer
Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.
question
return
answer
The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
question
def
answer
Define a function.
question
for
answer
Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.// Defines a variable to store each iteration as the generator counts through. // The for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. ex. words = ['cat', 'window', 'defenestrate'] for w in words: print w, len(w)
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
try
answer
Specifies exception handlers and/or cleanup code for a group of statements.
question
True
answer
Boolean true ex. x = x
question
False
answer
Boolean false. ex. y = x
question
None
answer
Absence of a value.
question
strings
answer
A sequence characters which mathematical functions cannot be performed on. ex. "Hello world"
question
numbers
answer
A sequence of numbers that math can be performed on. ex. 1, 3, 4, 9938
question
floats
answer
Represent real numbers and are written with a decimal point dividing the integer and fractional parts. Floats may also be in scientific notation, with E or e indicating the power of 10. ex. 1.0, 3.0, 4.0, 99.38, 2.5e2
question
lists
answer
Mutable sequence of elements that can be iterated through. ex. (1, 3, blue, apple)
question
'
answer
Escape Sequence; Single quote(')
question
"
answer
Escape Sequence; Double quote(")
question
a
answer
Escape Sequence; ASCII Bell (BEL)
question
b
answer
Escape Sequence; Backspace
question
f
answer
Escape Sequence; ASCII Formfeed
question
n
answer
Escape Sequence; New Line
question
r
answer
Escape Sequence; Carriage Return
question
t
answer
Escape Sequence; Horizontal Tab
question
v
answer
Escape Sequence; Vertical Tab
question
%d
answer
Signed decimal
question
%i
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 point 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. Uppercase exponential format if less than -4, decimal format otherwise
question
%c
answer
Single character.
question
%r
answer
String, converts using repr(), "x"
question
%s
answer
Strong, 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 to
question
>=
answer
greater than or equal to
question
==
answer
comparison, equal to
question
!=
answer
comparison, not equal to
question
()
answer
tuple
question
[]
answer
list
question
{}
answer
set
question
=
answer
Declaration of a variable
question
+=
answer
Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand. ex. c += a is equivalent to c = c + a
question
-=
answer
Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand. ex. c -= a is equivalent to c = c - a
question
*=
answer
Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand. ex. c *= a is equivalent to c = c * a
question
/=
answer
Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand. ex. c /= a is equivalent to c = c / a
question
//=
answer
Floor Dividion and assigns a value, Performs floor division on operators and assign value to the left operand. ex. //= a is equivalent to c = c // a
question
%=
answer
Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand. ex. c %= a is equivalent to c = c % a
question
**=
answer
Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand. ex. c **= a is equivalent to c = c ** a