Python Data Types, Variables and Keywords (With Examples)

Python Data Types and Variables – With the full keywords list

Quick answer: Python’s built-in data types are numeric (int, float, complex), boolean (bool), text (str), sequence (list, tuple, range), mapping (dict), set (set, frozenset), binary (bytes, bytearray, memoryview) and NoneType. Variables are names that point to these objects – Python decides the type automatically at runtime. Python 3 has 35 reserved keywords such as if, for, def, class and return, which cannot be used as variable names.

All examples below were run on Python 3.13; the outputs shown are real.

Python Data Types at a Glance

CategoryTypeExampleMutable?
Numericint10, -5, 2024No
Numericfloat3.14, 2.5e3No
Numericcomplex2 + 3jNo
BooleanboolTrue, FalseNo
Textstr“Python”No
Sequencelist[1, 2, 3]Yes
Sequencetuple(1, 2, 3)No
Sequencerangerange(5)No
Mappingdict{“E”: 200}Yes
Setset / frozenset{1, 2}, frozenset({1, 2})Yes / No
Binarybytes / bytearrayb”hi”, bytearray(b”hi”)No / Yes
NoneNoneTypeNoneNo

Checking a Data Type with type()

x = 10
y = 3.14
z = 2 + 3j
name = "Python"
flag = True
print(type(x), type(y), type(z), type(name), type(flag))

Output:

<class 'int'> <class 'float'> <class 'complex'> <class 'str'> <class 'bool'>

Numeric Types: int, float and complex

int stores whole numbers of any size. float stores decimal numbers using double precision, so some decimals cannot be stored exactly – this is why 0.1 + 0.2 == 0.3 is False. Use round() or math.isclose() when comparing floats. complex numbers have a real and imaginary part and are used in electrical and vibration calculations.

Strings (str)

A string is an immutable sequence of characters. You can index, slice and loop over it, but you cannot change a character in place:

s = "hello"
try:
    s[0] = "H"
except TypeError as e:
    print("Error:", e)

Output:

Error: 'str' object does not support item assignment

Lists

A list is an ordered, mutable collection – you can add, remove and change items.

parts = ["bolt", "nut", "washer"]
parts.append("gear")
parts[0] = "screw"
print(parts, len(parts))

Output:

['screw', 'nut', 'washer', 'gear'] 4

Tuples

A tuple is an ordered, immutable collection. It is used for fixed data such as coordinates, and can be unpacked into variables.

point = (3, 4)
x, y = point
print(x, y)

Output:

3 4

Dictionaries

A dictionary stores key–value pairs and gives fast lookup by key. Since Python 3.7 it keeps insertion order.

material = {"name": "Steel", "E_GPa": 200, "density": 7850}
material["yield_MPa"] = 250
print(material["E_GPa"], list(material.keys()))

Output:

200 ['name', 'E_GPa', 'density', 'yield_MPa']

Sets

A set stores unique items and supports union (|), intersection (&) and difference (−).

a = {1, 2, 3, 3}
b = {3, 4}
print(a, a | b, a & b)

Output:

{1, 2, 3} {1, 2, 3, 4} {3}

Type Conversion (Casting)

print(int("25") + 5, float("2.5") * 2, str(100) + "%", list("abc"), bool(0), bool("hi"))

Output:

30 5.0 100% ['a', 'b', 'c'] False True

Empty values – 0, 0.0, “”, [], {}, set() and None – are False in a boolean context; almost everything else is True.

Python Variables

A variable is a name that refers to an object. There is no declaration step – assigning a value creates the variable, and its type comes from the value.

  • Names can contain letters, digits and underscores, but cannot start with a digit.
  • Names are case-sensitive: Stress and stress are different.
  • Keywords cannot be used as names.
  • Use lowercase_with_underscores for variables (PEP 8), e.g. yield_strength.
  • Multiple assignment works: a, b = 5, 9.

Python Keywords List

Python 3.13 has 35 keywords (check with keyword.kwlist):

FalseNoneTrueandas
assertasyncawaitbreakclass
continuedefdelelifelse
exceptfinallyforfromglobal
ifimportinislambda
nonlocalnotorpassraise
returntrywhilewithyield

Python also has soft keywords – match, case, _ and type – which act as keywords only in specific statements (such as pattern matching) and can still be used as names elsewhere.

import keyword
print(len(keyword.kwlist))

Output:

35

Mutable vs Immutable Data Types

Mutable (can change)Immutable (cannot change)
list, dict, set, bytearrayint, float, complex, bool, str, tuple, frozenset, bytes

Immutable objects can be dictionary keys and set items; mutable objects cannot.

Frequently Asked Questions

How many data types are there in Python?

Python has about 15 built-in data types grouped into numeric (int, float, complex), bool, str, sequence (list, tuple, range), mapping (dict), set (set, frozenset), binary (bytes, bytearray, memoryview) and NoneType.

What is the difference between list and tuple?

A list is mutable and written with square brackets; a tuple is immutable and written with parentheses. Tuples are used for fixed data and can be dictionary keys.

How many keywords are there in Python?

Python 3.13 has 35 keywords, plus the soft keywords match, case, _ and type.

Is Python dynamically typed?

Yes. The type of a variable is decided at runtime from the value assigned to it, and the same name can later refer to a value of a different type.

Why is 0.1 + 0.2 not equal to 0.3 in Python?

Floats are stored in binary, and 0.1 and 0.2 cannot be represented exactly, so the sum is 0.30000000000000004. Use round() or math.isclose() for comparisons.

Related Python Guides

Scroll to Top