NO TWELVE HOUR TIME PERMITTED BEYOND THIS POINT
We apologise for any inconvenience caused by our programming
There now follows a ranking of the top keywords in Python 3. Criteria included importance [do you use it a lot?], usefulness [does it come in handy even if you don’t use it a lot?], and intuitiveness [does it make sense that it was chosen to represent that concept?].
- for: Loop that iterates through a sequence. Equivalent to
foreach in other programming languages, which is usually what is needed anyway. Also used for list comprehensions and generator expressions, which are two of the most awesome things that exist in Python.
- in: Boolean operator that tests whether an item is in a sequence, a key is in a dictionary, or a substring is within a string. Also used with
- if: Defines a conditional block.
- finally: Closing portion of a
try block. Always executed, even if the
try block raised an exception. Extraordinarily useful for making sure files, databases, and other shared resources are closed even if there is an exception.
- try: Defines an exception handling block. Requires either an
except block or a
finally block, or both.
- return: Exits a function with the specified return value. If no value is specified, returns
- with: Executes a context manager: an object that defines how to initialise and close itself. Automates common
with open('new_cooker.txt') as f:.
- while: Loop that repeats as long as the specified condition is true.
- class: Defines a class.
- as: Used in
except statements to assign something to an identifier.
- None: The null object. Capitalised because it is an object. Usually used as a default for optional function arguments. Amusingly, prior to Python 3,
None was not a keyword, but still a builtin object, which meant that you could assign something else to it:
None = 'blancmange'.
- True: Boolean true. Capitalised because it is an object. Amusingly, prior to Python 3,
True was not a keyword, but still a builtin object, which meant that you could assign something else to it:
True = False.
- False: Boolean false. Capitalised because it is an object. Amusingly, prior to Python 3,
False was not a keyword, but still a builtin object, which meant that you could assign something else to it:
False = True.
- import: Imports a module. With
from, imports a module from a package, or specific identifiers from a module.
- else: Last alternative in a conditional block, exceptionless alternative in a
try block, and closing block of a
while loop. This last usage is helpful if you need to know whether a loop exited normally or through a
- not: Boolean not operator. Also used as part of comparison operators
not in and
- and: Boolean and operator.
- or: Boolean or operator. Disappointingly, Python has no xor operator.
- def: Defines a function or class method. One is inevitably left to wonder why Guido was too lazy to type out
- lambda: Defines an anonymous function. Useful when sorting, eg:
silly_walks.sort(key = lambda walk: walk['name'])
- from: Used with
import to import a module from a package, or specific identifiers from a module.
- yield: Returns a value from a generator. Automatically makes a function a generator, which can be suspended and resumed. Useful to define an object that returns data a bit at a time instead of all at once, which can clog memory.
- except: Catches an exception from a
try block. Multiple
except blocks may be used to test for different types of exceptions.
- raise: Raises an exception.
- elif: Alternative test in a conditional block. Programming languages must come together on this and use
elif like Python, and definitely not
elsif like Perl.
- break: Escapes from a
while loop, and skips the
- continue: Returns to the beginning of a
while loop. If the last iteration, proceeds to the
- pass: NOOP. Useful when declaring a stub class, like a custom exception type. Uses the “passing spins” sound from Press Your Luck.
- global: Declares an identifier as global.
- nonlocal: Declares an identifier as nonlocal, ie, from the enclosing scope. Useful when defining nested functions.
- del: Deletes an identifier, list item, dictionary key, or attribute.
- is: Boolean operator that tests whether two items are identical.
- assert: Debugging assertion. Still a reserved word, but more and more seems as though it should be turned into a function, like
PLEASE SEND ALL INCOHERENT RANTS TO <GOOBNET@GOOBNET.NET>
© 2018 GOOBNET ENTERPRISES, INC [WHICH DOESN’T ACTUALLY EXIST HOWEVER]
THIS FILE ACCURATE AS OF: · GENERATED IN SECONDS