I want to know how we can print a string with number without space like this : hello1232 but, print('hello' 1232) have error. I need to write a program to print something like this : Hello0001 Hello0002 ... Hello3424 pls help me!
CodePudding user response:
print('hello' str(1232))
You can't add a string and an int, so you convert the int to a string with str().
CodePudding user response:
There are a lot of ways you can accomplish this, here's just a sample:
print('hello' '1232') # number enclosed in strings (you can't do on a string with an integer)
print('hello' str(1232)) # number directly converted to a string
print(f'hello{1232}') # f-strings are powerful, useful, and the most efficient
If you want to learn more about f-strings (you should, they're great), here are some guides you can check out to get started:
