Introduction to Python

Data Types in Python

Lesson 4: Variables and Data Types

What are Data Types?

Every value in Python has a data type that tells Python what kind of data it is and what operations can be performed on it. Understanding data types is essential for writing correct programs.

The 4 Core Data Types

The number 42 displayed in bold representing the integer data type
int — Whole Numbers
The number 3.14 displayed representing the float decimal data type
float — Decimals
The word Hello in quotation marks representing the string text data type
str — Text
True and False labels with a toggle switch representing the boolean data type
bool — True / False

Python Data Types

Data TypeKeywordExampleDescription
Integerintage = 15Whole numbers, positive or negative
Floatfloatheight = 1.75Decimal numbers
Stringstrname = "Tobi"Text — always in quotes
Booleanboolis_student = TrueTrue or False values only

Checking Data Types

You can check the data type of any variable using the type() function.

name = "Tobi" age = 15 height = 1.75 is_student = True print(type(name)) # <class 'str'> print(type(age)) # <class 'int'> print(type(height)) # <class 'float'> print(type(is_student)) # <class 'bool')

Type Conversion

Sometimes you need to convert a value from one data type to another. This is called type conversion or type casting.

Diagram showing arrows between data types — a string 25 being converted to integer 25 and float 25.0, with the int(), float(), and str() function labels on the arrows

Type Conversion Functions

FunctionConverts ToExample
int()Integerint("15") → 15
float()Floatfloat("3.14") → 3.14
str()Stringstr(100) → "100"
bool()Booleanbool(0) → False
When getting input from a user with input(), Python always returns a string. If you need a number, you must convert it using int() or float()!

Subscribe to our newsletter.

Get updates to news and events.