PythonPython Data TypesData Type Conversions

Data Type Conversions

Python provides several functions to convert between data types:

  • int(): Converts input to an integer.
  • float(): Converts input to a float.
  • str(): Converts input to a string.
  • chr(): Converts an integer to its Unicode character.
  • bool(): Converts input to True or False.
  • type(): Displays the data type of a variable.

For example:

age = "25"
print(type(age))          # Output: <class 'str'>
 
age = int(age)            # Convert to integer
print(type(age))          # Output: <class 'int'>