Python Forum
Im using python crash course version 2 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Im using python crash course version 2 (/thread-20945.html)



Im using python crash course version 2 - james_newbie - Sep-07-2019

i want to use \n \t in a variable and print


name = " JOHN "
print(name.lstrip())
print(name.rstrip())
print(name.strip())
print("\tname")
print("\nname")
it gives an error on this print("\tname")
print("\nname")

sorry i canĀ“t find box parentice


RE: Im using python crash course version 2 - ichabod801 - Sep-07-2019

What error is it giving you? Or is it just not printing what you expected? Perhaps you meant:

print('\t', name)
or

print(f'\t{name}')



RE: Im using python crash course version 2 - james_newbie - Sep-07-2019

(Sep-07-2019, 09:14 PM)ichabod801 Wrote: What error is it giving you? Or is it just not printing what you expected? Perhaps you meant:

print('\t', name)
or

print(f'\t{name}')




it print name istead of john
JOHN
JOHN
JOHN
name

name

so it ses name as a string i think and not as a variable


RE: Im using python crash course version 2 - ichabod801 - Sep-07-2019

Right. Things in quotes are strings, not variable names. You need to take them out of the quotes (my first example) or use a special string syntax so that they are recognized as variables (my second example).