Integer To String In Python
Chapter:
Python
Last Updated:
22-10-2021 02:48:36 UTC
Program:
/* ............... START ............... */
number = 20
# check and print type of num variable
print(type(number))
# convert the num into string
converted_num = str(number)
# check and print type converted_num variable
print(type(converted_num))
/* Output
<class 'int'>
<class 'str'>
*/
name = "John"
age = 23
print(name + " is " + str(age) + " years old")
/* Output
John is 23 years old
*/
/* ............... END ............... */
Notes:
-
To convert integer to string in python , we have to use str() function. This function takes any data type and convert it to a string.
- In the above program you can see that by using type function it is printing as number in first step and by using str(number) it will convert to string format.
- After converting to string , by using type(converted_num) you can see that it is converted to String.
- Normally programmers use str() function to concatenate string and Integer type.(Please refer the second program).
Tags
integer to string in python, Python Int to String , str() fuction in Python