[NooB] Using Escape Sesquences with Strings...

A

administrata

Hello! :)
I've reading 'Python Programmin for the Absolute beginner'.
I got questions which is...

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""
print \trock

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

error occurs!

I don't know how to \t The variable.

Help!
 
D

Daniel Bickett

administrata said:
print \trock

Your problem lies in this line. The escape sequence \t is not a
variable, so to speak. It is just that, an escape sequence, so it must
be located inside of a string:

print "\t" + rock
 
B

bruno modulix

administrata said:
Hello! :)
I've reading 'Python Programmin for the Absolute beginner'.
I got questions which is...

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""
print \trock

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

error occurs!

I don't know how to \t The variable.

see Daniel's answer for the why.
Now for the how, I guess you want a tab on each line so you have two
solutions :
1/ putting the tabs in the string:
rock = """
\tIgneous Sedimentary Metamorphic

\tLava Grains Marble
\tRamdom crystals Layer Bands
\tGranite Salt Schist
\tIntrusive Weathering Heat + Pressure
\t Deposition Change"""

print rock

2/ adding the tabs before printing:
rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""


for line in rock.split("\n"):
print "\t%s" % line

HTH,
 
A

administrata

bruno modulix said:
see Daniel's answer for the why.
Now for the how, I guess you want a tab on each line so you have two
solutions :
1/ putting the tabs in the string:
rock = """
\tIgneous Sedimentary Metamorphic

\tLava Grains Marble
\tRamdom crystals Layer Bands
\tGranite Salt Schist
\tIntrusive Weathering Heat + Pressure
\t Deposition Change"""

print rock

2/ adding the tabs before printing:
rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""


for line in rock.split("\n"):
print "\t%s" % line

HTH,

thx 4 your helpful msg.

I'll input 1 instead of 2 which is a bit complicated for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,219
Messages
2,571,118
Members
47,737
Latest member
CarleyHarm

Latest Threads

Top