- 1
how to combine string ng integer?
3 Answers
+ 2
print('đ'+str(5))
+ 1
another method to do this would be to put f before the quotation marks and curly brackets around each number you want to put, like so:
print(f"I am {5} years old")
I find this way to be easier to read and to write.
+ 1
Hi Zeref!
There are many ways to combine a string with an integer.
name = "James"
age = 20
1. Using normal addition or String concatenation
print('my name is ' + name + 'my age is ' + str(age))
2. Using comma as separator
print('my name is', name, 'my age is ',age))
3. Using f-string
print(f'my name is {name} my age is {age}')
4. Using .format()
print("my name is {name} my age is {age}".format(name=name, age=age))
5. Using the % operator
print("my name is %s my age is %i" % (name, age))