I see you guys using
url = '"%s"' % url # This part
>>> url = "http://www.site.com/info.xx"
>>> print url
http://www.site.com/info.xx
>>> url = '"%s"' % url
>>> print url
"http://www.site.com/info.xx"
Is it advanced Python? Is there a tutorial for it? How can I learn about it?
-
5You've marked both questions as duplicates. Surely you'd mark only the latter (chronologically)Anti Earth– Anti Earth2012年12月30日 06:35:17 +00:00Commented Dec 30, 2012 at 6:35
-
No, it's like twins. Both should be destroyed.thumbtackthief– thumbtackthief2013年07月23日 16:14:14 +00:00Commented Jul 23, 2013 at 16:14
3 Answers 3
It's common string formatting, and very useful. It's analogous to C-style printf formatting. See String Formatting Operations in the Python.org docs. You can use multiple arguments like this:
"%3d\t%s" % (42, "the answer to ...")
answered Feb 12, 2009 at 21:43
dwc
25k7 gold badges47 silver badges55 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Janusz Lenar
The real answer is 43 but don't tell anyone.
AWE
@Janusz Lenar blasphemy, I will not flag you this time but big brother is keeping an eye on you now.
Sandeep Singh Rawat
Url is broken => Correct Url docs.python.org/3/library/string.html#formatstrings
That line of code is using Python string formatting. You can read up more on how to use it here: http://docs.python.org/library/stdtypes.html#string-formatting
answered Feb 12, 2009 at 21:37
Dan Lew
87.8k33 gold badges184 silver badges177 bronze badges
Comments
It is not advanced, you can use ' or " to define a string.
Check the documentation.
answered Feb 12, 2009 at 21:37
Andrea Ambu
39.8k14 gold badges57 silver badges77 bronze badges
Comments
lang-py