๐Ÿ“ Python

Python Data Types: A Complete Guide ๐ŸŽฏ

P
Author
PyLand Team
๐Ÿ“…
Published
30.03.2026
โฑ๏ธ
Reading time
4 min
๐Ÿ‘๏ธ
Views
400
๐ŸŒฑ
Level
Beginner

Python can work with different types of data: numbers, text, boolean values. Let’s cover all the fundamental types!

๐Ÿ“Š Core Data Types

1. int โ€” Integers

age = 25
year = 2026
temperature = -15
big_number = 1000000

print(type(age))  # <class 'int'>

Where it’s used: counters, ages, quantities, years

2. float โ€” Floating-Point Numbers

height = 1.75
price = 99.99
pi = 3.14159
temperature = -5.5

print(type(height))  # <class 'float'>

Where it’s used: heights, prices, percentages, coordinates

3. str โ€” Strings (Text)

name = 'Anna'
city = "New York"
message = '''Multi-line
text'''

print(type(name))  # <class 'str'>

Where it’s used: names, addresses, messages, any text

4. bool โ€” Boolean Type

is_student = True
has_license = False

print(type(is_student))  # <class 'bool'>

Where it’s used: condition checks, state flags

๐Ÿ”„ Type Conversion

String โ†’ Number

# String โ†’ Integer
age_str = '25'
age_int = int(age_str)
print(age_int + 5)  # 30

# String โ†’ Float
price_str = '99.99'
price_float = float(price_str)
print(price_float * 2)  # 199.98

# โš ๏ธ Error if the string is not a number!
int('abc')  # ValueError!

Number โ†’ String

age = 25
age_str = str(age)
print('I am ' + age_str + ' years old')  # I am 25 years old

# Or use f-strings (easier!)
print(f'I am {age} years old')  # I am 25 years old

To Boolean

# Any non-zero number โ†’ True
bool(1)      # True
bool(100)    # True
bool(-5)     # True
bool(0)      # False

# Any non-empty string โ†’ True
bool('text')  # True
bool('')      # False (empty string)

๐ŸŽฏ Common Mistakes

Mistake 1: Concatenating a string and a number

# โŒ TypeError!
age = 16
print('I am ' + age + ' years old')  # Error!

# โœ… Convert the number to a string
print('I am ' + str(age) + ' years old')

# โœ… Or use an f-string
print(f'I am {age} years old')

# โœ… Or separate with a comma
print('I am', age, 'years old')

Mistake 2: Dividing integers always yields a float

print(10 / 2)   # 5.0 (float!)
print(10 // 2)  # 5 (int)

# Even when the division is exact
result = 10 / 2
print(type(result))  # <class 'float'>

Mistake 3: True/False must be capitalized

# โŒ Error!
is_active = true   # NameError!

# โœ… Correct
is_active = True
is_ready = False

๐Ÿ’ก Checking Types

age = 25

# Get the type
print(type(age))  # <class 'int'>

# Check the type
if isinstance(age, int):
    print('This is an integer')

if isinstance('text', str):
    print('This is a string')

๐Ÿ”ข Operations with Different Types

int + int โ†’ int

a = 10
b = 5
print(a + b)       # 15 (int)
print(type(a + b)) # <class 'int'>

int + float โ†’ float

a = 10     # int
b = 5.5    # float
print(a + b)       # 15.5 (float)
print(type(a + b)) # <class 'float'>

str + str โ†’ str

first = 'Hello'
second = 'world'
print(first + ' ' + second)  # Hello world

str * int โ†’ str

print('๐Ÿ”ฅ' * 5)     # ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ
print('ha' * 3)     # hahaha

๐ŸŽจ String Specifics

Quotes

# Single quotes
name = 'Anna'

# Double quotes
city = "New York"

# Triple quotes (multi-line text)
message = '''
First line
Second line
Third line
'''

Escape Characters

# Newline
print('First\nSecond')

# Tab
print('Name:\tAnna')

# Quote inside a string
print('He said: \'Hello!\'')

Indexing

text = 'Python'

print(text[0])   # P (first character)
print(text[1])   # y (second character)
print(text[-1])  # n (last)
print(text[-2])  # o (second-to-last)

๐Ÿš€ Practical Examples

Example 1: Type Calculator

num1 = int(input('First number: '))
num2 = int(input('Second number: '))

print(f'{num1} + {num2} = {num1 + num2}')
print(f'Type: {type(num1 + num2)}')

num3 = float(input('Floating-point number: '))
print(f'{num1} + {num3} = {num1 + num3}')
print(f'Type: {type(num1 + num3)}')

Example 2: Converter

# String โ†’ Number โ†’ String
age_str = input('Age: ')
age_int = int(age_str)
doubled = age_int * 2
result = str(doubled)

print(f'Doubled age: {result}')

Example 3: Type Checking

value = input('Enter something: ')

# Check what was entered
if value.isdigit():
    print('That is a number!')
    number = int(value)
    print(f'Doubled: {number * 2}')
elif value.isalpha():
    print('That is text!')
    print(f'Uppercase: {value.upper()}')
else:
    print('That is something else')

๐Ÿ“‹ Cheat Sheet

# Data types
int    # Integer: 10, -5, 0
float  # Float: 3.14, -0.5, 99.99
str    # String: 'text', "text"
bool   # Boolean: True, False

# Conversions
int('123')      # '123' โ†’ 123
float('3.14')   # '3.14' โ†’ 3.14
str(456)        # 456 โ†’ '456'
bool(1)         # 1 โ†’ True

# Checks
type(x)              # Get the type
isinstance(x, int)   # Check the type
value.isdigit()      # String of digits?
value.isalpha()      # String of letters?

๐ŸŽ“ Summary

  • int โ€” integers (10, -5, 0)
  • float โ€” floating-point numbers (3.14, 99.99)
  • str โ€” text (‘hello’, “world”)
  • bool โ€” True or False
  • Convert types with: int(), float(), str(), bool()
  • Python infers the type when a variable is created
  • You cannot add numbers and strings directly!

Understanding data types is the key to writing error-free code! ๐Ÿ’ช

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

if __name__ == "__main__": the Python entry point

The if name == "main" guard defines a Python program's entry point: it distinguishes direct...

๐Ÿ“… 14.08.2026 ๐Ÿ‘๏ธ 44
๐Ÿ“

strip() and lower(): Preparing User Text ๐Ÿงน

A user may enter the correct word with extra spaces or different letter case. Python...

๐Ÿ“… 11.08.2026 ๐Ÿ‘๏ธ 50
๐Ÿ“

ord(), chr(), and Cyclic Letter Shifts in Python ๐Ÿ”

A string contains characters, but a computer stores every character as a numeric code. Python...

๐Ÿ“… 09.08.2026 ๐Ÿ‘๏ธ 89