<class 'int'>
Similarly, we can assign a boolean, a string, or a float value to a variable and print its data type.
x = True print(type(x)) y = 1.4 print(type(y)) z = "John" print(type(z))
The output of the above program will be:
<class 'bool'> <class 'float'> <class 'str'>
Now, let’s say we want to assign a float value 1.0 to a variable. We can easily specify the data type of a variable while assigning a value to it. For example,
n = float(1) print(n) print(type(n))
The above program should print the following output:
1.0 <class 'float'>
Similarly, we can create a variable l and assign a list to it.
l = list(("a", "b", "c"))
print(l)
print(type(l))
The output will be:
['a', 'b', 'c'] <class 'list'>








































0 Comments