- 1

how to combine string ng integer?

2nd Nov 2021, 12:07 AM
Zeref Dragneel
Zeref Dragneel - avatar
3 odpowiedzi
+ 2
print('👋'+str(5))
2nd Nov 2021, 12:15 AM
Solo
Solo - avatar
+ 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.
2nd Nov 2021, 12:21 AM
Ben Eshchar
Ben Eshchar - avatar
+ 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))
2nd Nov 2021, 3:20 AM
Python Learner
Python Learner - avatar