Built-in Types in Python
Created
Modified
Core Data Types
The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions.
Built-in objects preview:
Object type:
Numbersint, float, complex.Strings'spam', "Bob's", b'a\x01c', u'sp\xc4m'Lists[1, [2, 'three'], 4.5],list(range(10))Dictionaries{'food': 'spam', 'taste': 'yum'},dict(hours=10)Tuples(1, 'spam', 4, 'U'),tuple('spam'),namedtupleFilesopen('eggs.json')Setsset('abc'),{'a', 'b', 'c'}Other core typesBooleans, types, NoneProgram unit typesFunctions, modules, classesImplementation-related typesCompiled code, stack tracebacks
Numeric Types
There are three distinct numeric types: integers, floating point numbers, and complex numbers.
# Built-in Types
# Numeric Types
import math
# Integer addition
print(123+345)
# 2 to the power 100, again
print(2**100)
# math module
print(math.pi)
468 1267650600228229401496703205376 3.141592653589793
Sequence Types
There are three basic sequence types: lists, tuples, and range objects.
# Built-in Types
# Sequence Types
# in operations
print("yt" in "byte")
# lists
lists = [[]] * 3
lists = [[] for i in range(3)]
print(lists)
True [[], [], []]
Mapping Types
A mapping object maps hashable values to arbitrary objects. Mappings are mutable objects.
# Built-in Types
# Mapping Types
d = dict(a=1, b=2, c=3)
e = {'a':1, 'b':2}