Today we are goint to discuss about the basic datatypes in python
Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data.
Int is type of integer numbers without decimal points, it can be less than or greter than orequal to zero.
if we declare a variable with integer values its type will be int,
a = 10; b = 20; #type of a and b is int
float is type of numbers with decimal points, it can be less than or greter than orequal to zero.
if we assign a number with decimal points to a variable, its type will be float,
a = 10.5; b = 20.4; c = 3.14 #type of a and b and c is float
string is type of sentences or phrase declared and wrapped within single or double quotes. When we display a text with the
print() function the output itself is a string.
a = "hello world"
here the type of
a is string.
a string is a sequence of characters, we can calculate the total number of characters present in a string.
to calculate the total characters present in a string python has a built-in function
total_Characters = len("hello world") print(total_characters)
We can pull out specific character from a string, its called subscripting.
text = "hello world" print(text) # text means the the first characters of a text string, in python or any other programming language the counting or first index starts with 0 (zero)
Boolean type of variable holds only two values
False we use booleans to check if any specific expression is true or false. Its used in conditonal programming.
first_answer = True second_answer = False
first_answer holds a Boolean type value
True and the
second_answer holds the
to check type of variables python has a built-in function
a = 100 b = 10.50 c = "i am a string" d = True print("The type of a is", type(a)) print("The type of b is", type(b)) print("The type of c is", type(c)) print("The type of d is", type(d))
output: The type of a is <class 'int'> The type of b is <class 'float'> The type of c is <class 'str'> The type of d is <class 'bool'>
If you like the content and want to get updates on more post like that please follow me @rhythmsaha
here are my social profiles