Bottom Page

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
ichabod801 wrote Sep-07-2019, 09:12 PM:
Square brackets are generally typed with the same keys as curly brackets, just without the shift key.
Quote
#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

Quote
#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
Quote
#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

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  update certbot's python version metulburr 0 87 Sep-19-2019, 11:51 AM
Last Post: metulburr
  Python 3 crash course james_newbie 6 251 Aug-25-2019, 08:23 PM
Last Post: snippsat
  [split] Using this Python version of text2pdf jonsnow1221 1 221 May-07-2019, 07:48 PM
Last Post: micseydel
  Using this Python version of text2pdf Pedroski55 1 321 Apr-15-2019, 08:12 AM
Last Post: Pedroski55
  can't install package web in version python 3.7 a21250450 1 337 Mar-29-2019, 11:28 AM
Last Post: Larz60+
  Python Version on Mac OSX Sparkstorm 5 413 Feb-06-2019, 10:32 AM
Last Post: Sparkstorm
  Python version 3 that seems to be ignored by the system on a Raspberry Pi Discret68 3 500 Dec-28-2018, 06:42 PM
Last Post: Gribouillis
  How to comapare version UUIDs in python? swamyjrs 3 420 Dec-19-2018, 08:57 AM
Last Post: Gribouillis
  Python version compatability saisankalpj 5 499 Nov-29-2018, 06:12 PM
Last Post: nilamo
  python kernell crash with a ctypes program Jstechg 1 559 Nov-24-2018, 02:37 PM
Last Post: Jstechg

Forum Jump:


Users browsing this thread: 1 Guest(s)