+ 1
Iâm new and canât figure out why I canât print spaces
name = "James" age = "42" print ((name + "is")+ (age + "years old")) The solution(sorry Iâm still learning terms) is Jamesis42years old I googled spaces and have tried ââ and a couple other things but it still wonât run Thanks
4 Antworten
+ 3
You have to actually put a space inside the quotation marks. E.g. to print a single space use
" "
+ 2
you could also use formatted strings, in order to print what you are trying to print with spaces, simply type the following:
print (f"{name} is {age} years old")
This allows you to put variables directly into the string, rather than having to format it afterwards or use the "+" operator. simply put a lowercase "f" before your strings in order to integrate variables in this way
+ 2
Hi Chris!
Someone asked the same thing a few weeks ago. So, I'm sharing this with you to understand the concept clearly
https://www.sololearn.com/discuss/2850362/?ref=app
+ 1
As Simon Sauter pointed out, the most simple way is to use:
print((name + â is â) + (age + â years oldâ)
Note that I have used spaces inside the quotation marks.
Another way is to use commas to seperate members inside the âprintâ fuction, and the function will automatically add a space between members.
Try this:
print(âabcâ, âdefâ)
Output:
abc def