Python Reference
Python Reference
Python Reference
Built-in Functions
String Methods
List Methods
Dictionary Methods
Tuple Methods
Set Methods
File Methods
Keywords
Exceptions
Glossary
Python Built in Functions
Python has a set of built-in functions.
Function Description
abs() Returns the absolute value of a number
delattr() Deletes the specified attribute (property or method) from the specified object
divmod() Returns the quotient and the remainder when argument1 is divided by argument2
hasattr() Returns True if the specified object has the specified attribute (property/method)
map() Returns the specified iterator with the specified function applied to each item
range() Returns a sequence of numbers, starting from 0 and increments by 1 (by default)
Note: All string methods returns new values. They do not change the original string.
Method Description
capitalize() Converts the first character to upper case
endswith() Returns true if the string ends with the specified value
find() Searches the string for a specified value and returns the position of where it was
found
index() Searches the string for a specified value and returns the position of where it was
found
isalpha() Returns True if all characters in the string are in the alphabet
isascii() Returns True if all characters in the string are ascii characters
islower() Returns True if all characters in the string are lower case
isupper() Returns True if all characters in the string are upper case
partition() Returns a tuple where the string is parted into three parts
replace() Returns a string where a specified value is replaced with a specified value
rfind() Searches the string for a specified value and returns the last position of where it was
found
rindex() Searches the string for a specified value and returns the last position of where it was
found
rpartition() Returns a tuple where the string is parted into three parts
rsplit() Splits the string at the specified separator, and returns a list
split() Splits the string at the specified separator, and returns a list
startswith() Returns true if the string starts with the specified value
swapcase() Swaps cases, lower case becomes upper case and vice versa
zfill() Fills the string with a specified number of 0 values at the beginning
Note: All string methods returns new values. They do not change the original string.
Python List/Array Methods
Python has a set of built-in methods that you can use on lists/arrays.
Method Description
append() Adds an element at the end of the list
extend() Add the elements of a list (or any iterable), to the end of the current list
index() Returns the index of the first element with the specified value
Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.
Python Dictionary Methods
Python has a set of built-in methods that you can use on dictionaries.
Method Description
clear() Removes all the elements from the dictionary
items() Returns a list containing a tuple for each key value pair
setdefault() Returns the value of the specified key. If the key does not exist: insert the key, with
the specified value
Method Description
count() Returns the number of times a specified value occurs in a tuple
index() Searches the tuple for a specified value and returns the position of where it was found
Python Set Methods
Python has a set of built-in methods that you can use on sets.
Method Description
add() Adds an element to the set
difference() Returns a set containing the difference between two or more sets
difference_update() Removes the items in this set that are also included in another,
specified set
intersection_update() Removes the items in this set that are not present in other, specified
set(s)
symmetric_difference_update() inserts the symmetric differences from this set and another
update() Update the set with another set, or any other iterable
Python File Methods
Python has a set of methods available for the file object.
Method Description
close() Closes the file
fileno() Returns a number that represents the stream, from the operating system's perspective
seekable() Returns whether the file allows us to change the file position
Keyword Description
and A logical operator
as To create an alias
finally Used with exceptions, a block of code that will be executed no matter if there is an
exception or not
or A logical operator
Exception Description
ArithmeticError Raised when an error occurs in numeric calculations
EOFError Raised when the input() method hits an "end of file" condition (EOF)
NotImplementedError Raised when an abstract method requires an inherited class to override the
method
RuntimeError Raised when an error occurs that do not belong to any specific exceptions
StopIteration Raised when the next() method of an iterator has no further values
Feature Description
Indentation Indentation refers to the spaces at the beginning of a code line
Global Variables Global variables are variables that belongs to the global scope
Strings are Arrays Strings in Python are arrays of bytes representing Unicode characters
Evaluate Booleans Evaluate a value or statement and return either True or False
Identity Operators Identity operators are used to see if two objects are in fact the same object
Tuple With One Item How to create a tuple with only one item
The pass Keyword in If Use the pass keyword inside empty if statements
While Continue How to stop the current iteration and continue wit the next
For Continue How to stop the current iteration and continue wit the next
For pass Use the pass keyword inside empty for loops
Function Recursion Functions that can call itself is called recursive functions
What is an Array Arrays are variables that can hold more than one value
Access Arrays How to access array items
The Class __init__() The __init__() function is executed when the class is initiated
Function
Object Methods Methods in objects are functions that belongs to the object
self The self parameter refers to the current instance of the class
super Function The super() function make the child class inherit the parent class
Using the dir() List all variable names and function names in a module
Function
The strftime Method How to format a date object into a readable string
Date Format Codes The datetime module has a set of legal format codes
Format JSON How to format JSON output with indentations and line breaks
RegEx Sets A set is a set of characters inside a pair of square brackets with a special
meaning
RegEx Match Object The Match Object is an object containing information about the search
and the result