Python Forum
Im using python crash course version 2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Im using python crash course version 2
#1
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
Reply
#2
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}')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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
Reply
#4
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).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  run part of a script with a different version of Python jdog 2 395 Jan-09-2024, 08:49 PM
Last Post: jdog
  How to find out from outside Python (in Windows) the current version of Python? pstein 4 680 Oct-04-2023, 10:01 AM
Last Post: snippsat
  How to resolve version conflicts in Python? taeefnajib 0 873 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  Python venv and PIP version issue JanOlvegg 2 1,200 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Python Version upgrade nitinkukreja 1 855 Feb-04-2023, 10:27 PM
Last Post: Larz60+
  Can't update new python version on Pycharm GOKUUUU 6 3,712 Jul-23-2022, 09:24 PM
Last Post: GOKUUUU
  Building python (3.9.5) with different libexpat version (2.4.6) raghupcr 0 1,262 Feb-25-2022, 11:29 AM
Last Post: raghupcr
  Python keeps running the old version of the code quest 2 3,647 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime
  Catching a crash within a library code ebolisa 9 3,069 Nov-22-2021, 11:02 AM
Last Post: bowlofred
  Python Crash Course ( 2nd edition) alok 1 1,845 Jul-19-2021, 05:55 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020