Skip to content

Instantly share code, notes, and snippets.

@hawkz
Created July 15, 2012 22:34
Show Gist options
  • Save hawkz/3118961 to your computer and use it in GitHub Desktop.
Save hawkz/3118961 to your computer and use it in GitHub Desktop.
Python in 33 sentences
print - lets you output numbers and characters to the console.
if - let's you choose which statements are executed if an expression is true
else - denotes the statements that execute if the expression isn't true
elif - let's you combine if statements
while - is a way of repeating statements in a loop until an expression is false.
break - is a way to jump out of the statement flow of a loop.
continue - let's you skip a cycle of the flow without ending it.
for - is used to iterate over items of a collection in the order they appear in a container
is - tests objects to see if they're the same
not - turns a true to false and a false to a true
and - is tests for multiple conditions to be true
or - tests for one or more conditions to be true
in - tests to see if an object is inside a container
import - is used to load other modules into your script
as - is used to give modules we load a new name
from - lets us limit what parts of a module we import
def - helps you organise and re-use your code as a function
return - tells a function what to pass back when it's called
lambda - creates a new anonymous function
global - lets functions access objects outside their scope
try - let's you group statements to help catch exceptions
except - let's you run statements when exceptions occur
raise - let's you create an exception
finally - executes statements after all exceptions are done
with - let's you execute statements with a context guard
del - deletes an object
pass - does nothing at all, but is handy
assert - let's is add boolean tests for debugging
class - let's us wrap statements in an object
exec - let's you run python code dynamically
yield - let's you create a generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment