Show Menu
Cheatography

Built-in Data Types Cheat Sheet (DRAFT) by

Built-in Data Types in Python

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Text Type

String - str
"­Hello World"
'Hello World'
Strings in Python are surrounded by either single quotation marks, or double quotation marks.

Numeric Types

Integers - int
10, -145, 500
Floati­ng-­point numbers - float
2.5, 50.005, 89.95
Complex numbers - complex
5j, 2+1j, 55j
Integer is a whole number, positive or negative, without decimals, of unlimited length. Float is a number, positive or negative, containing one or more decimals. Complex numbers are written with a "­j" as the imaginary part.

Sequence Types

Lists - list
fruits = ['apple', 'banana', 'pear']
Tuples - tuple
fruits = ('apple', 'banana', 'pear')
Range( ) - range
range(start, stop, step)
List items are ordered, change­able, and allow duplicate values. Tuple items are ordered, unchan­geable, and allow duplicate values. Range( ) returns a sequence of numbers, starting from 0 by default.
 

Mapping Type

Dictio­naries - dict
dict = {'key': 'value', 'key': 'value'}
Dictionary items are presented in key:value pairs. Dictionary items are ordered, change­able, and does not allow duplic­ates.

Set Types

Sets - set
fruits = {'apple', 'banana', 'pear'}
Frozen sets - frozenset
frozenset(iterable)
A set is a collection which is unordered, unchan­geable, and unindexed. The frozen sets are the immutable form of the normal sets.

Boolean Types

Booleans - bool
True, False
Booleans represent one of two values: True or False.

Binary Types

Bytes - bytes
b"He­llo­"
Bytearray - bytearray
bytear­ray(5)
Memoryview - memoryview
memory­vie­w(b­yte­s(5))
Bytes and bytearray are used for manipu­lating binary data. The memoryview uses the buffer protocol to access the memory of other binary objects without needing to make a copy.