Data Types in Python — int , float, string, boolean
Python has several built-in data types that are used to represent different kinds of values. Some of the most commonly used data types in Python are as shown below:
Integer
Integers are whole numbers, both positive and negative, without any decimal point.
It contains positive or negative whole numbers. Eg, 1, 2, 50, -20, 10
x = 10
y = -5
Float
It represents real numbers with floating point. Eg, 2.5, 25.23
fnum = 34.45
print(fnum)
Output
34.45
String
String contains sequence of characters. It represents by using single quotes, double quotes or triple quotes. It is denoted by the class str.
str = "My name"
print(str)
Output
My name
Boolean
Boolean represents True and False values. It is denoted by the class bool.
a = True
type(a)
Output
<class 'bool'>
The output <class ‘bool’> indicates the variable is a Boolean data type.
The keywords True and False must have an Upper Case first letter. lowercase true and false returns an error.
Thanks for reading!
I hope you found this story valuable. If you have any questions or insights to share, please feel free to leave your comments. Your inputs will contribute to enhancing the quality of the content.
Thank you for your support!!
For more insights like these, feel free to 👏 follow 👉 Shilpa Sreekumar