By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

[NooB] a Variable in multiple quotes...

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
It's OK for me
@-salutations
--
Michel Claveau
Jul 18 '05 #2

P: n/a
administrata wrote:
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
Jul 18 '05 #3

P: n/a
administrata wrote:
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.
'I am John' is """I am John""" True

Point 3: To print using what you call variables:
I = 'John'
print I, 'used to ...' John used to ... print '%s used to ...' % I John used to ... I = 'Fred'
print '%s used to ...' % I Fred used to ... print I, 'used to ...' Fred used to ...
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]:
print '%(I)s used to ...' % locals()

Fred used to ...

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

HTH,

John

Jul 18 '05 #4

P: n/a
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
--
Michael Hoffman
Jul 18 '05 #5

P: n/a
Michael Hoffman wrote:
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.

--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #6

P: n/a
Leif K-Brooks <eu*****@ecritters.biz> wrote in message news:<37*************@individual.net>...
administrata wrote:
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


How can I do it with several variables?

About 10 or more...

HELP plz :)
Jul 18 '05 #7

P: n/a
"administrata" wrote:
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...


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>

Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.