Python quick reference

Common built-ins and methods on one page.

Built-inPurpose
print(x)Show a value
input(text)Read a line typed by the user, as a string
len(x)Number of items
range(a, b)Numbers from a up to, but not including, b
int() / float() / str()Convert a value
sum() / min() / max()Total, smallest and largest
sorted(x)A new sorted list
enumerate(x)Pairs of index and item for a loop
zip(a, b)Walk two sequences together
MethodPurpose
s.strip()Remove spaces from both ends
s.split(",")Break a string into a list
",".join(items)Join a list into a string
s.lower() / s.upper()Change case
list.append(x)Add to the end
list.pop()Remove and return the last item
list.sort()Sort in place
dict.get(k, d)Value for k, or d if it is missing
dict.items()Key and value pairs for a loop
  • Virtual environment: python -m venv .venv keeps project packages separate.
  • Install a package: pip install requests
  • Save your packages: pip freeze > requirements.txt
โ† Classes and objectsPython learning path โ†’