Python Forum

Full Version: Im using python crash course version 2
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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}')
(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
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).