+ 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

24th Aug 2021, 12:08 AM
Chris Crowley
Chris Crowley - avatar
4 ответов
+ 3
You have to actually put a space inside the quotation marks. E.g. to print a single space use " "
24th Aug 2021, 12:23 AM
Simon Sauter
Simon Sauter - avatar
+ 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
24th Aug 2021, 12:33 AM
V Karch
V Karch - avatar
+ 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
24th Aug 2021, 1:59 AM
Python Learner
Python Learner - avatar
+ 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
24th Aug 2021, 1:16 PM
Wenkai Qu
Wenkai Qu - avatar