Python
Last updated
Last updated
python [filename]
python3 [filename]
if __name__ == "__main__":
Error Types: Exception
(most general?)| RuntimeError
|TypeError
|OSError
etc
Capture exception info
and
and or
0, '', [], (), {}, and None are false
Actually return one of the values being computed
'a' and 'b'
returns 'b'
'' and 'b'
return ''
So, 1 and a or b
is basically the trinary operator(unless a is false)
(1 and [a] or [b])[0] is the safe way
They are the same
is
checks they point to the same thing i.e [1,2,3] is not [1,2,3] but [1,2,3] == [1,2,3]
Use is None
because a class could define == to be different and is is faster
dir(nltk)
- lists all functions in package
*args
will give you all function parameters as a tuple
**kwargs
will give you all keyword arguments as a dictionary expect acutal args
Pass in dict like f(**dict)
to act as **kwargs
lambda x, y: x[1] + y
PYTHON 2: input("Enter number")
interprets user input so if int, int will be returned(Security bug, runs arbitrary code use raw_input)
raw_input("Enter Your Name: ")
takes exactly what user typed
PYTHON 3: input
is raw_input
Can also use