[NooB] a Variable in multiple quotes...

A

administrata

Is it possible?

I tried...


I = "John"
print \
"""
I used to love pizza"""


Error occurs!!!

But, I don't know how to fix... HELP

thx 4 reading.
 
L

Leif K-Brooks

administrata said:
Is it possible?

I tried...

I = "John"
print \
"""
I used to love pizza"""


Error occurs!!!

No error occurs; it prints "I used to love pizza", as would be expected.

Oh: from the subject line, I'm guessing that you want it to say "John
used to love pizza" instead? In that case, try doing this:

I = "John"
print "%s used to love pizza" % I
 
J

John Machin

administrata said:
Is it possible?

I tried...


I = "John"
print \
"""
I used to love pizza"""


Error occurs!!!

But, I don't know how to fix... HELP

thx 4 reading.

Point 0: It helps if you post a copy of what the actual screen display
looked like, instead of just saying "Error occurs!!!".

It helps in that people are more likely to be bothered helping you,
instead of just writing you off as clueless and unclueable -- and as
you have chosen to try Python, you can't be utterly beyond redemption
:)

Point 1: So, which error? Let's guess:

You got something like this:

! print \
! ^
!SyntaxError: invalid token

If so, that is very likely because you had one or more spaces after the
\. Backslash means line-continuation only if it is the LAST character
in the line.

If not, see point 0.

Point 2: so-called multiple quotes: this is nothing to do with your
problem. The different ways of quoting differ only in what characters
like other quotes and newlines can appear inside the quotes.
True

Point 3: To print using what you call variables:

Point 4: How far through the Python tutorial have you progressed?

Point 5: If some bright spark suggests something like the following,
ignore them until you are up to speed on points[:5]:
Fred used to ...

Point 6: If you don't understand the meaning of [:5], refer to point 4.

HTH,

John
 
M

Michael Hoffman

You know, it's really not necessary for you to put "[NooB]" in the subject
of your posts. This is a fairly friendly group and they will answer even
newbie questions amicably. But if you want an even kinder, gentler place to
ask questions as a newbie (not a noob), I suggest the Tutor mailing list:

http://mail.python.org/mailman/listinfo/tutor
 
N

Nick Coghlan

Michael said:
This is a fairly friendly group and they will answer even
newbie questions amicably.

Albeit with the occasional pointed comment about not at least skimming the
tutorial when it covers the question asked ;)

Cheers,
Nick.
 
A

administrata

Leif K-Brooks said:
No error occurs; it prints "I used to love pizza", as would be expected.

Oh: from the subject line, I'm guessing that you want it to say "John
used to love pizza" instead? In that case, try doing this:

I = "John"
print "%s used to love pizza" % I

How can I do it with several variables?

About 10 or more...

HELP plz :)
 
F

Fredrik Lundh

administrata said:
How can I do it with several variables?

About 10 or more...

two:

print I, "used to love", J

or

print "%s used to love %s" % (I, J)

three:

print I, "used to", J, K
print "%s used to %s %s" % (I, J, K)

five:

print I, J, "to", K, L, M
print "%s %s to %s %s %s" % (I, J, K, L, M)

(you get the idea)

for more on this, and some variations, read the "fancier output
formatting" chapter in the tutorial again:

http://docs.python.org/tut/node9.html

(you've read the tutorial before, right?)

</F>
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top