+ 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 ответов
+ 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