KEYWORD | DESCRIPTION | EXAMPLE |
---|---|---|
and | Logical and. | True and False == False |
as | Part of the with-as statement. | with X as Y: pass |
assert | Assert (ensure) that something is true. | assert False, "Error!" |
break | Stop this loop right now. | while True: break |
class | Define a class. | class Person(object) |
continue | Don't process more of the loop, do it again. | while True: continue |
def | Define a function. | def X(): pass |
del | Delete from dictionary. | del X[Y] |
elif | Else if condition. | if: X; elif: Y; else: J |
else | Else condition. | if: X; elif: Y; else: J |
except | If an exception happens, do this. | except ValueError, e: print e |
exec | Run a string as Python. | exec 'print "hello"' |
finally | Exceptions or not, finally do this no matter what. | finally: pass |
for | Loop over a collection of things. | for X in Y: pass |
from | Importing specific parts of a module. | import X from Y |
global | Declare that you want a global variable. | global X |
if | If condition. | if: X; elif: Y; else: J |
import | Import a module into this one to use. | import os |
in | Part of for-loops. Also a test of X in Y. | for X in Y: pass also 1 in [1] == True |
is | Like == to test equality. | 1 is 1 == True |
lambda | Create a short anonymous function. | s = lambda y: y ** y; s(3) |
not | Logical not. | not True == False |
or | Logical or. | True or False == True |
pass | This block is empty. | def empty(): pass |
Print this string. | print 'this string' | |
raise | Raise an exception when things go wrong. | raise ValueError("No") |
return | Exit the function with a return value. | def X(): return Y |
try | Try this block, and if exception, go to except. | try: pass |
while | While loop. | while X: pass |
with | With an expression as a variable do. | with X as Y: pass |
yield | Pause here and return to caller. | def X(): yield Y; X().next() |
Wednesday, May 6, 2015
Python: Some Keywords
Location:
PaulSofTech, Dhaka, Bangladesh
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment