expected result:
What is your name? *name*
So your name is 'name' huh?
code :
name = input("What is your name? ")
print('So your name is ' , 'name' ,'?')
i need help on the second line of my code!
Try this:
name = input("What is your name? ")
print("So your name is '{0}'?".format(name))
To solve issues like this only both single ' and double " quotes are allowed in python strings.
Also note I've use the string.format() function to format the string otherwise it would be ugly and would look like:
print("So your name is '" + name + "'?")
Use string formatting with double quotes:
>>> name="user3094915"
>>> print("So your name is '%s'" % name)
So your name is 'user3094915'
In general, you could use ", ', """ and ''' as string delimiters in Python. Whenever you need to put a quite in your string, simply delimit the string with a different type.
The other way is escaping your quotes with \, e.g. \' or \". This is the classic way, and almost every other programming language uses this idiom, which arguably makes your code more readable to non-Pythonists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With