i'm trying to code a game but it keeps popping up with can only concatenate str (not "int") to str
and i tried print('sample text' + variable + 'sample text')
Asked
Active
Viewed 94 times
-2

RonaB
- 5
- 2
-
4duplicate of: https://stackoverflow.com/questions/961632/converting-integer-to-string-in-python – silicontrip Apr 22 '21 at 03:05
-
E. g. something like "str(5)" – Michael Butscher Apr 22 '21 at 03:06
-
if python 3 you can use f-strings i.e. `print(f'sample text {variable} sample text')` – GRAYgoose124 Apr 22 '21 at 03:11
-
3Does this answer your question? [Converting integer to string in Python](https://stackoverflow.com/questions/961632/converting-integer-to-string-in-python) – CozyAzure Apr 22 '21 at 03:13
2 Answers
2
You can either cast to str
or use an f-string (format string).
print('sample text' + str(variable) + 'sample text')
or
print(f'sample text {variable} sample text')

will-hedges
- 1,254
- 1
- 9
- 18