I want to do a challenge for beginner python course and one of the challenges is to print a name and age name= "John" age= "24" print (name + 'is' + age 'years old') and the output is: Johnis24years old how can i add space between john , is , 24 and years?
4/25/2021 9:43:57 PM
Mwsdo3 Answers
New Answer1. You can add commas print(name, "is", age, "years old") 2. using f-string print(f"{name} is {age} years old") 3. using the sep argument print(name, "is", age, "years old", sep=" "*4) More info: https://code.sololearn.com/c76OnygcB39j/?ref=app
use 2 spaces before and after " is " and 1 space before " years." Like this print(name+" is "+age+" years")
Use the space in double quote like ...+ " is " + ...+ " years old " And, If you need to make new line, use this: print("\n")
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message