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

Conversion to string: how do `s work?

P: n/a
I'm working my way through _Learning_Python_ 2nd ed., and I saw
something peculiar which is not explained anywhere in the text.

print " " + file + " size=" + `size`

The `s appear to somehow automagically convert the integer to a string
for concatenation. How does this work? Is this just a shortcut for
str(size)? Is it considered bad practice to use `s?

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chris Lasher wrote:
The `s appear to somehow automagically convert the integer to a string
for concatenation. How does this work? Is this just a shortcut for
str(size)?
No, it's a shortcut for repr(size).
Is it considered bad practice to use `s?


Yes, please don't do it. I can't remember ever seeing it in production
code, so many people wouldn't even know what it was. And ' vs. ` is
confusing.
--
Michael Hoffman
Jul 18 '05 #2

P: n/a
Ah, repr. Did not cross my mind. Good to see my suspicions about the
use of ` being poor practice were correct. "Explicit is better than
implicit."

Thanks for the reply.

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.