[NooB] Using Escape Sesquences with Strings...

bruno modulix onurb at xiludom.gro
Fri Feb 11 09:17:44 EST 2005


administrata wrote:
> 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,
-- 
bruno desthuilliers
ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| 
p.split('.').collect{|w| w.reverse}.join('.')}.join('@')"
--



More information about the Python-list mailing list