Python Data Types

1. What is a Data Type?

A data type tells Python what kind of value a variable is storing.

Example:

  • Number

  • Text

  • True or False

Python understands data types automatically.

2. Common Data Types in Python

Python has many data types, but beginners should first learn these:

  1. Integer (int)

  2. Float (float)

  3. String (str)

  4. Boolean (bool)

3. Integer (int)

An integer is a whole number.
It can be positive, negative, or zero.

Examples

age = 25
count = -10
number = 0

print(age)
print(count)
print(number)

4. Float (float)

A float is a number with decimal point.

Examples

price = 19.99
pi = 3.14

print(price)
print(pi)

5. String (str)

A string is text.
It is written inside quotes (" " or ' ').

Examples

name = "Python"
city = 'Delhi'

print(name)
print(city)

Joining Strings

first = "Hello"
second = "World"

print(first + " " + second)

Length of a String

word = "Python"
print(len(word))

6. Boolean (bool)

A boolean has only two values:

  • True

  • False

Used for decisions.

Examples

is_active = True
is_raining = False

print(is_active)
print(is_raining)

7. Checking Data Type (type())

You can check the data type of a variable.

Example

x = 10
print(type(x))

name = "Amit"
print(type(name))

8. Type Conversion (Type Casting)

Sometimes we need to change one data type to another.

String to Integer

x = "10"
y = int(x)
print(y + 5)

Integer to Float

a = 5
b = float(a)
print(b)

Number to String

age = 20
print("Age is " + str(age))

9. Input and Data Types

Input from user is always string.

Example

age = input("Enter age: ")
print(type(age))

Convert it:

age = int(input("Enter age: "))
print(type(age))

10. Simple Practice Examples

Example 1: Add Two Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Sum:", a + b)

Example 2: Print User Details

name = input("Enter name: ")
age = int(input("Enter age: "))

print("Name:", name)
print("Age:", age)

11. Common Beginner Mistakes

❌ Mixing Text and Number

age = 20
print("Age is " + age)

✔ Correct:

print("Age is", age)

❌ Forgetting Conversion

num = input("Enter number: ")
print(num + 5)

✔ Correct:

num = int(input("Enter number: "))
print(num + 5)

12. Summary (Python Data Types)

✔ Data types tell value type
✔ Common types: int, float, str, bool
✔ Python detects type automatically
type() checks data type
✔ Conversion is important

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Python Numbers (deep)

  • Python Strings (easy)

  • Boolean & Conditions

  • Data Type Exercises

  • MCQs with answers

Just tell me 😊

You may also like...