Video Pending

Created by Zed A. Shaw Updated 2024-02-17 04:54:36

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.


andLogical and.True and False == False
asPart of the with-as statement.with X as Y: pass
assertAssert (ensure) that something is true.assert False, "Error!"
breakStop this loop right now.while True: break
classDefine a class.class Person(object)
continueDon't process more of the loop, do it again.while True: continue
defDefine a function.def X(): pass
delDelete from dictionary.del X[Y]
elifElse if condition.if: X; elif: Y; else: J
elseElse condition.if: X; elif: Y; else: J
exceptIf an exception happens, do this.except ValueError as e: print(e)
execRun a string as Python.exec 'print("hello")'
finallyExceptions or not, finally do this no matter what.finally: pass
forLoop over a collection of things.for X in Y: pass
fromImporting specific parts of a module.from x import Y
globalDeclare that you want a global X
ifIf condition.if: X; elif: Y; else: J
importImport a module into this one to use.import os
inPart of for-loops. Also a test of X in Y.for X in Y: pass also 1 in [1] == True
isLike == to test equality.1 is 1 == True
lambdaCreate a short anonymous function.s = lambda y: y ** y; s(3)
notLogical not.not True == False
orLogical or.True or False == True
passThis block is empty.def empty(): pass
printPrint this string.print('this string')
raiseRaise an exception when things go wrong.raise ValueError("No")
returnExit the function with a return value.def X(): return Y
tryTry this block, and if exception, go to except.try: pass
whileWhile loop.while X: pass
withWith an expression as a variable do.with X as Y: pass
yieldPause here and return to caller.def X(): yield Y; X().next()
Previous Lesson Back to Module

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.