Video Coming Soon...
37: Symbol Review
It's time to review the symbols and Python words you know and to try to pick up a few more for the next few lessons. I have written out all the Python symbols and keywords that are important to know.
In this lesson take each keyword and first try to write out what it does from memory. Next, search online for it and see what it really does. This may be difficult because some of these are difficult to search for, but try anyway.
If you get one of these wrong from memory, make an index card with the correct definition and try to "correct" your memory.
Finally, use each of these in a small Python program, or as many as you can get done. The goal is to find out what the symbol does, make sure you got it right, correct it if you did not, then use it to lock it in.
Keywords
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 as 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. | from x import 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 | 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() |
Register for Learn Python the Hard Way, 5th Edition (2023-2024)
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.