Determining Type

Output



<class 'str'> <class 'int'> <class 'float'>
Code
x = "Hello"
y = 5
z = 6.7
print(type(x))
print(type(y))
print(type(z))

Converting Types

Output

5.7 <class 'str'>

5.7 <class 'float'>

5 <class 'int'>
Code
x = "5.7"
print(x)
print(type(x))
print()
y = float(x)
print(y)
print(type(y))
print()
z = int(y)
print(z)
print(type(z))

Exceptions

a = "5.7"
print(a)
print(type(a))
print()
b = int(a)
print(b)
print(type(b))

Exceptions

a = "5.7"
print(a)
print(type(a))
print()
b = int(a)
print(b)
print(type(b))

Exceptions

a = "5.7"
print(a)
print(type(a))
print()
b = int(a)
print(b)
print(type(b))

Traceback (most recent call last):
File "tutor.py", line 5, in <module>
    b = int(a)
ValueError: invalid literal for int() with base 10: '5.7'