
Data Types in Python – Part 1
Data types tell Python what kind of data a variable contains. Python has different data types for storing different kinds of values.
In this part, we will learn about Numbers, Strings, and Boolean.
1. Integer (int)
An integer is used to store whole numbers.
age = 21
print(age)Output:
212. Float (float)
A float is used to store numbers with decimal values.
price = 99.50
print(price)Output:
99.53. Complex (complex)
Complex numbers contain a real part and an imaginary part.
number = 2 + 3j
print(number)Output:
(2+3j)4. String (str)
A string is used to store text.
name = "Vishnu"
print(name)Output:
VishnuStrings can be written using single or double quotes.
5. Boolean (bool)
Boolean is used when a value can be True or False.
is_logged_in = True
print(is_logged_in)Output:
TrueChecking the Data Type
We can use the type() function to check the type of a value.
age = 21
name = "Vishnu"
print(type(age))
print(type(name))Output:
<class 'int'>
<class 'str'>Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments