There are three main data types in Python: numbers, strings, and
booleans.
Numbers- This includes integers and floating-point
numbers.
Strings - This includes textual data.
Booleans - This includes True and False values.
Converting Data Types in Python
Python has several built-in functions for converting the types of
our variables. For example, we have the int () function for
converting a value to an integer:
= "1982 "aqge = 2020 -
birth_year
int (birth year) print ("You are + str (age) +
years old. ")
In the above example, we use the int() function to convert
the birth year string to an integer sO we can subtract it from
the current year.
We also have the float () function for converting a value to a
float:
num "10.5"float num =
float (num) print (float _num)
In the above example, we use the float () function to convert
the num string to a floating point number.
booleans.
Numbers- This includes integers and floating-point
numbers.
Strings - This includes textual data.
Booleans - This includes True and False values.
Converting Data Types in Python
Python has several built-in functions for converting the types of
our variables. For example, we have the int () function for
converting a value to an integer:
= "1982 "aqge = 2020 -
birth_year
int (birth year) print ("You are + str (age) +
years old. ")
In the above example, we use the int() function to convert
the birth year string to an integer sO we can subtract it from
the current year.
We also have the float () function for converting a value to a
float:
num "10.5"float num =
float (num) print (float _num)
In the above example, we use the float () function to convert
the num string to a floating point number.