Data Types & Variables
Python - A Quick Start for existing Programers
2 min read
Published Sep 16 2025, updated Aug 17 2026
Guide Sections
Guide Comments
In Python, variables do not have their types declared and are automatically assigned types based on the contents at run time.
Variables should be declared using lower case, snake case, eg. my_variable. Variable names are case sensitive, so My_Variable is considered different to my_variable.
There is no concept of constants in Python. Standard practice is to use capitalised variables for constants as a naming convention, however, these are still variables so can be changed. eg. MY_CONSTANT.
Basic data types
NoneType : represents Nothing, or No Value:
x = Noneint : integer values:
x = 4No minimum or maximum number, only restricted by memory available.
float : floating point numbers (decimals):
x = 4.3Smallest number 2.2250738585072014e-308, largest number 1.7976931348623157e+308, Anything beyond that becomes inf (infinity).
complex : complex numbers:
A complex number has two parts:
- a real part (like an ordinary number)
- an imaginary part (multiplied by
jin Python, which represents √-1)
a + bjwhere
a= real part (float or int)b= imaginary part (float or int)j= imaginary unit
You write j (not i, as in math) to denote the imaginary unit:
x = 3 + 5j# Access the real number part -> 3.0print(x.real) # Access the imaginary number part -> 5.0print(x.imag) Minimum and maximums are the same as for float for each part.
bool : boolean (True or False):
is_valid = TrueText data type
str : string (sequence of Unicode characters), wrapped in single or double quotes:
name = "Pete"animal = 'Frog'No maximum length, only restricted by memory available.
Multi value data types
list : ordered, mutable collection, wrapped in square brackets:
fruits = ["apple", "banana", "cherry"]tuple : ordered, immutable collection, wrapped in standard brackets:
point = (10, 20)set : unordered collection of unique elements, wrapped in curly brackets:
colors = {"red", "green", "blue"}dict : dictionary of key-value pairs:
person = { "name": "Ana", "age": 30, "country": "UK"}bytes : immutable sequence of bytes:
b = b"hello"bytearray : mutable sequence of bytes:
ba = bytearray([65, 66, 67])Casting one data type to another
Each data type has a function that can be called to cast data from one type to another:
# Casting to an integerint(3.9) # = 3int("42") # = 42# Casting to a floatfloat(5) # = 5.0float("3.14") # = 3.14# Casting to a complex (real part = x, imag = 0)complex(5) # = (5+0j)complex(2, 3) # = (2+3j)# Casting to a stringstr(123) # = "123"str(3.14) # = "3.14"# Casting to a listlist("abc") # = ['a', 'b', 'c']# Casting to a tupaltuple([1, 2]) # = (1, 2)# Casting to a setset([1, 2, 2, 3]) # = {1, 2, 3}# Casting to a dictionarydict([(1, "a"), (2, "b")]) # = {1: 'a', 2: 'b'}# Casting to bytesbytes("hi", "utf-8") # = b'hi'# Casting to a mutable version of bytesbytearray([65, 66, 67]) # = bytearray(b'ABC')Checking a variables type
The built-in type() function returns the type (class) of an object:
x = 42print(type(x)) # <class 'int'>y = "hello"print(type(y)) # <class 'str'>You can use the type() function for a direct comparison:
x = 3.14if type(x) is float: print("x is a float")Note: This checks for an exact match, not subclasses.
Using isinstance() is safer and more flexible, because it works with inheritance:
x = 3.14if isinstance(x, float): print("x is a float")# Multiple typesif isinstance(x, (int, float)): print("x is a number")You can use issubclass() to check if a class is derived from another class:
print(issubclass(bool, int)) # True (in Python, bool is a subclass of int)