Convert to String in Python
To convert a number to a string, you need to apply the str function. Let's use this function to make a string out of a number:
test1 = 'abc'
test2 = 1
test3 = test1 + str(test2)
print(test3) # 'abc1'
Given variables:
num1 = 1
num2 = 2
Add these variables as strings:
'12'
Given variables:
tst1 = 'abc'
txt2 = 123
Add these variables as strings:
'abc123'
Given a number:
tst = 123
Find the number of digits of this number.
Given a number:
tst = 456
Find the sum of the digits of this number.