Show Menu

**Python Data Types** Cheat Sheet (DRAFT) by

Document for python data types

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

Data Types In Python

Numbers :
> Python supports three types of numbers: integers, floati­ng-­point numbers, and complex numbers.
> Integers are whole numbers without a decimal point, floati­ng-­point numbers have a decimal point,
and complex numbers have both real and imaginary compon­ents.
x = 5 # integer
y = 3.14 # floati­ng-­point number
z = 2 + 3j # complex number

Lists In Python

Lists are ordered sequences of values that can be of any data type.
They are mutable, which means that you can add, remove, or modify elements in a list.
fruits = ["ap­ple­", "­ban­ana­", "cherry"]
print(fruits) # output: ["ap­ple­", "­ban­ana­", "cherry"]
print(fruits) # output: ["ap­ple­", "­ban­ana­", "­che­rry­", "orange"]
print(fruits) # output: ["ap­ple­", "­che­rry­", "­ora­nge­"]

Booleans In Python

Boolean values represent either True or False.
They are used for logical operations and control flow statem­ents, such as if-else statements and loops.
is_raining = True
is_sunny = False
print("Bring an umbrella")
print("Enjoy the sunshi­ne")

Strings in Python

Strings are sequences of characters that are enclosed in single or double quotes.
They can be manipu­lated in various ways, such as concat­ena­tion, slicing, and formatting
message = "­Hello, World!"
print(message) # output: Hello, World!
print(message[0]) # output: H
print(message[7:12]) # output: World
formatted_message = "My name is {} and I am {} years old".fo­rma­t("J­ohn­", 25)
print(formatted_message) # output: My name is John and I am 25 years old

Tuples In Python

Tuples are similar to lists in that they are ordered sequences of values,
but they are immutable, which means that you cannot modify them after they are created
coordinates = (10, 20)
print(coordinates) # output: (10, 20)
x, y = coordinates
print(x) # output: 10

Dict­ion­aries in Python

Dictio­naries are unordered collec­tions of key-value pairs, where each key is unique.
They are commonly used for data modeling and organizing data.
person = {"na­me": "­Joh­n", "­age­": 25, "­add­res­s": "123 Main St"}
print(person) # output: {"na­me": "­Joh­n", "­age­": 25, "­add­res­s": "123 Main St"}
print(person["name"]) # output: John
person["phone"] = "555-1234"
print(person) # output: {"na­me": "­Joh­n", "­age­": 25, "­add­res­s": "123 Main St", "­pho­ne": "­555­-12­34"}