Python Data Types Explained for Beginners (int, float, string, bool)
Python Data Types Explained for Beginners (int, float, string, bool)
By Ayush Gupta
Introduction
In the previous post, we learned about Python variables. Now let’s understand what type of data those variables can store.
Python has different data types, and in this post, we will focus on the four most important ones:
- int
- float
- string
- bool
What is a Data Type?
A data type tells Python what kind of value a variable is holding. Based on the data type, Python decides how the data should be stored and used.
1️⃣ Integer (int)
An integer is a whole number without a decimal point.
age = 21
marks = 90
print(age)
print(marks)
Examples of integers:
- 10
- -5
- 0
2️⃣ Float (float)
A float is a number that contains a decimal point.
price = 99.50
percentage = 87.75
print(price)
print(percentage)
3️⃣ String (str)
A string is used to store text. Text must be written inside single quotes or double quotes.
name = "Ayush"
course = 'Python Programming'
print(name)
print(course)
Strings can contain:
- Letters
- Numbers
- Symbols
4️⃣ Boolean (bool)
A boolean data type has only two possible values:
- True
- False
is_student = True
has_job = False
print(is_student)
print(has_job)
Checking the Data Type
You can check the data type of any variable using the type() function.
x = 10
y = 5.5
z = "Python"
a = True
print(type(x))
print(type(y))
print(type(z))
print(type(a))
Summary of Data Types
- int → Whole numbers
- float → Decimal numbers
- string → Text
- bool → True or False
What You Learned in This Post
- What data types are
- Integer, float, string, and boolean
- How to check a variable’s data type
What’s Next?
Now that you understand data types, the next step is learning how to take input from users.
Next Post: Python Input and Output Explained (input(), print())
---👋 About the Author
Ayush Gupta
MSc AI/ML Student | Machine Learning & Python Enthusiast
📧 Email:
aygupta9898@gmail.com
Comments
Post a Comment