WeCodeAcademy

Python Reference

Built-in functions and the methods of strings, lists, dictionaries and sets.

79 of 79
NameGroupDescription
print()Built-inPrints values to the screen.
input()Built-inReads a line typed by the user.
len()Built-inThe number of items in a sequence or collection.
type()Built-inThe type of a value.
int()Built-inConverts a value to an integer.
float()Built-inConverts a value to a decimal number.
str()Built-inConverts a value to a string.
bool()Built-inConverts a value to True or False.
list()Built-inMakes a list.
tuple()Built-inMakes a tuple.
set()Built-inMakes a set of unique values.
dict()Built-inMakes a dictionary.
range()Built-inA sequence of numbers.
sum()Built-inThe sum of an iterable of numbers.
min()Built-inThe smallest item.
max()Built-inThe largest item.
abs()Built-inThe absolute value.
round()Built-inRounds a number.
pow()Built-inRaises to a power.
divmod()Built-inQuotient and remainder.
sorted()Built-inA new sorted list.
reversed()Built-inAn iterator over items in reverse.
enumerate()Built-inPairs each item with its index.
zip()Built-inPairs items from several iterables.
map()Built-inApplies a function to every item.
filter()Built-inKeeps items where the function is true.
any()Built-inTrue if any item is true.
all()Built-inTrue if every item is true.
isinstance()Built-inWhether an object is of a type.
open()Built-inOpens a file.
str.upper()StringUpper-case copy of a string.
str.lower()StringLower-case copy of a string.
str.title()StringCapitalises each word.
str.strip()StringRemoves whitespace from both ends.
str.split()StringSplits a string into a list.
str.join()StringJoins items with a separator.
str.replace()StringReplaces text.
str.find()StringIndex of the first match, or -1.
str.startswith()StringWhether a string starts with text.
str.endswith()StringWhether a string ends with text.
str.count()StringCounts occurrences.
str.format()StringFills in placeholders.
str.isdigit()StringWhether all characters are digits.
str.zfill()StringPads with zeros on the left.
list.append()ListAdds an item to the end.
list.extend()ListAdds all items of another iterable.
list.insert()ListInserts an item at an index.
list.remove()ListRemoves the first matching item.
list.pop()ListRemoves and returns an item.
list.sort()ListSorts the list in place.
list.reverse()ListReverses the list in place.
list.index()ListThe index of the first match.
list.count()ListCounts occurrences.
list.copy()ListA shallow copy.
dict.get()DictionaryA value, or a default if missing.
dict.keys()DictionaryThe keys.
dict.values()DictionaryThe values.
dict.items()DictionaryKey and value pairs.
dict.update()DictionaryMerges another dictionary in.
dict.pop()DictionaryRemoves a key and returns its value.
dict.setdefault()DictionaryGets a key, adding it if missing.
set.add()SetAdds an item.
set.union()SetAll items from both sets.
set.intersection()SetItems in both sets.
set.difference()SetItems in a but not in b.
f-stringSyntaxA string with expressions inside braces.
list comprehensionSyntaxBuilds a list in one line.
lambdaSyntaxA small anonymous function.
try / exceptSyntaxHandles errors.
importSyntaxLoads a module.
math.sqrt()mathThe square root.
math.ceil()mathRounds up.
math.floor()mathRounds down.
math.pimathThe value of pi.
random.choice()randomA random item from a sequence.
random.randint()randomA random integer in a range.
datetime.datedatetimeWork with dates.
json.dumps()jsonConverts data to JSON text.
json.loads()jsonConverts JSON text to data.