๐Ÿ Python Dictionary

Every keyword, operator, and symbol โ€” with plain-English explanations.

abs BUILT-IN FUNCTIONS
Return the absolute value of the argument.
abs(-10) = 10
all BUILT-IN FUNCTIONS
Returns True if bool(x) is True for all elements x of the iterable.
all([True, True, True])
any BUILT-IN FUNCTIONS
Returns True if bool(x) is True for any x in the iterable.
any([False, False, True])
bin BUILT-IN FUNCTIONS
Returns the binary representation of an integer.
bin(10)
bool BUILT-IN FUNCTIONS
Returns the Boolean value of the specified object.
bool(0)
bytes BUILT-IN FUNCTIONS
Returns a new bytes object from the given object.
bytes([0x61, 0x62, 0x63])
bytearray BUILT-IN FUNCTIONS
Returns a new bytearray object, a mutable sequence of integers in the range 0 <= x < 256.
bytearray([0x61, 0x62, 0x63])
callable BUILT-IN FUNCTIONS
Returns whether the object is callable, that is, whether obj can be called as a function.
callable(print)
chr BUILT-IN FUNCTIONS
Returns a string representing a character whose Unicode code point is the integer i.
chr(65)
compile BUILT-IN FUNCTIONS
Compiles the source into a code or AST object.
compile('print("Hello")', '<string>', 'exec')
len BUILT-IN FUNCTIONS
Returns the number of items in an object (string, list, dict, etc.)
len([1,2,3])  # 3
len("hello")   # 5
complex BUILT-IN FUNCTIONS
Returns a complex number with the value real + imag*1j or converts a string or number to a complex number.
complex('1+2j')
print BUILT-IN FUNCTIONS
Prints objects to stdout, separated by sep, ending with end
print("hello", "world")   # hello world
print("x =", 42, end="\n")
delattr BUILT-IN FUNCTIONS
Deletes the named attribute from the specified object.
delattr(sys.modules[__name__], 'example')
range BUILT-IN FUNCTIONS
Returns a sequence of numbers from start to stop (exclusive) with given step
range(5)        # 0,1,2,3,4
range(1, 10, 2)  # 1,3,5,7,9
dict BUILT-IN FUNCTIONS
Returns a new dictionary with the specified values.
{'a': 1, 'b': 2}
list BUILT-IN FUNCTIONS
Creates a list from an iterable, or an empty list
list(range(3))  # [0, 1, 2]
list("abc")     # ['a', 'b', 'c']
dir BUILT-IN FUNCTIONS
Returns a list of the attributes and keys of the specified object.
dir(str)
divmod BUILT-IN FUNCTIONS
Returns the tuple (div, mod) such that a = b*div + mod and div is the quotient of a//b.
divmod(10, 3)
set BUILT-IN FUNCTIONS
Creates an unordered collection of unique elements
set([1,2,2,3])  # {1, 2, 3}
set("hello")   # {'h', 'e', 'l', 'o'}
enumerate BUILT-IN FUNCTIONS
Returns an enumerate object that produces a sequence of tuples containing indices and values of the iterable.
enumerate(['a', 'b', 'c'])
tuple BUILT-IN FUNCTIONS
Creates an immutable ordered sequence from an iterable
tuple([1,2,3])  # (1, 2, 3)
tuple("abc")   # ('a', 'b', 'c')
eval BUILT-IN FUNCTIONS
Evaluates the specified expression and returns the result.
eval('1 + 2')
str BUILT-IN FUNCTIONS
Creates or converts a value to a string
str(42)         # "42"
str([1,2,3])   # "[1, 2, 3]"
exec BUILT-IN FUNCTIONS
Executes the specified statement(s) or code object.
exec('print("Hello")')
int BUILT-IN FUNCTIONS
Creates or converts a value to an integer
int("42")   # 42
int(3.9)     # 3
filter BUILT-IN FUNCTIONS
Constructs an iterator from elements of an iterable for which a function returns true.
filter(lambda x: x > 0, [-1, 0, 1, 2])
float BUILT-IN FUNCTIONS
Converts a string or number to a floating point number.
float('123.456')
type BUILT-IN FUNCTIONS
Returns the type of an object, or creates a new type
type(42)       # <class 'int'>
type("hello")  # <class 'str'>
isinstance BUILT-IN FUNCTIONS
Returns True if the object is an instance of the given class or tuple of classes
isinstance(42, int)         # True
isinstance("hi", (int,str))  # True
frozenset BUILT-IN FUNCTIONS
Returns an immutable frozenset object initialized with elements from the specified iterable.
frozenset([1, 2, 3])
zip BUILT-IN FUNCTIONS
Aggregates elements from multiple iterables into tuples
zip([1,2,3], ["a","b","c"])
# (1,"a"), (2,"b"), (3,"c")
map BUILT-IN FUNCTIONS
Applies a function to every item of an iterable and returns an iterator
list(map(str, [1,2,3]))  # ["1","2","3"]
sorted BUILT-IN FUNCTIONS
Returns a new sorted list from an iterable
sorted([3,1,2])           # [1, 2, 3]
sorted([3,1,2], reverse=True)  # [3, 2, 1]
reversed BUILT-IN FUNCTIONS
Returns a reversed iterator over a sequence
list(reversed([1,2,3]))  # [3, 2, 1]
sum BUILT-IN FUNCTIONS
Sums the items of an iterable, starting from an optional initial value
sum([1,2,3])        # 6
sum([1,2,3], 10)   # 16
min BUILT-IN FUNCTIONS
Returns the smallest item in an iterable or among arguments
min([3,1,2])     # 1
min(3, 1, 2)  # 1
max BUILT-IN FUNCTIONS
Returns the largest item in an iterable or among arguments
max([3,1,2])     # 3
max(3, 1, 2)  # 3
open BUILT-IN FUNCTIONS
Opens a file and returns a file object
with open("file.txt", "r") as f:
    content = f.read()
input BUILT-IN FUNCTIONS
Reads a line from stdin; optional prompt string is displayed
name = input("Enter name: ")
age = int(input("Age: "))
format BUILT-IN FUNCTIONS
Formats a value according to a format spec; also available as str.format()
format(3.14159, ".2f")    # "3.14"
"{:.2f}".format(3.14159)  # "3.14"
round BUILT-IN FUNCTIONS
Rounds a number to a given number of digits
round(3.14159, 2)  # 3.14
round(2.5)         # 2
id BUILT-IN FUNCTIONS
Returns the identity (unique integer) of an object
id(42)     # e.g. 140234567
id("hi")   # unique int
hash BUILT-IN FUNCTIONS
Returns the hash value of an object
hash("hello")   # integer
hash((1,2,3))  # integer
help BUILT-IN FUNCTIONS
Displays help for an object, function, or module
help(str)    # str class docs
help(print)   # print function docs
vars BUILT-IN FUNCTIONS
Returns the __dict__ of an object, or local variables if no argument
class Foo:
    x = 1
vars(Foo())  # {'x': 1}
hasattr BUILT-IN FUNCTIONS
Returns True if the object has the named attribute
hasattr([], "append")  # True
hasattr(42, "upper")   # False
getattr BUILT-IN FUNCTIONS
Gets the value of a named attribute of an object
getattr([], "append")       # <method>
getattr(obj, "x", None)     # default if missing
setattr BUILT-IN FUNCTIONS
Sets the value of a named attribute of an object
setattr(obj, "x", 42)  # obj.x = 42
iter BUILT-IN FUNCTIONS
Returns an iterator object from an iterable
it = iter([1,2,3])
next(it)  # 1
next BUILT-IN FUNCTIONS
Returns the next item from an iterator
it = iter([1,2,3])
next(it)      # 1
next(it, 0)   # default when exhausted
super BUILT-IN FUNCTIONS
Returns a proxy object that delegates method calls to a parent class
class Child(Parent):
    def __init__(self):
        super().__init__()
property BUILT-IN FUNCTIONS
Creates a managed attribute with getter, setter, and deleter
class C:
    @property
    def x(self): return self._x
staticmethod BUILT-IN FUNCTIONS
Marks a method as a static method that does not receive self
class C:
    @staticmethod
    def greet(): return "hello"
classmethod BUILT-IN FUNCTIONS
Marks a method as a class method that receives the class as first argument
class C:
    @classmethod
    def create(cls): return cls()