• Data Type: how a value is stored
  • str: text data type
  • int: whole number data type
  • float: decimal number data type

Integers

x = 5

Integers

x = 5
y = -8

Floating-Point Values

a = 5.8



Floating-Point Values

a = 5.8
b = -7.987


Floating-Point Values

a = 5.8
b = -7.987
c = 42.0

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'