Category:Python: Difference between revisions

Content added Content deleted
(Undo revision 321087 by Hajo (talk) The version specified was for CPython. While that is a reference implementation, it's far from the only implementation)
m (port the example to python 3)
Line 15: Line 15:
===Notes===
===Notes===
Because Python uses whitespace for structure, do not format long code examples with leading whitespace, instead use <code><nowiki><pre></pre></nowiki></code> tags, or, preferably, <code><nowiki><lang python></lang></nowiki></code> tags. This will make it easier to copy code into and out of the wiki. Example:
Because Python uses whitespace for structure, do not format long code examples with leading whitespace, instead use <code><nowiki><pre></pre></nowiki></code> tags, or, preferably, <code><nowiki><lang python></lang></nowiki></code> tags. This will make it easier to copy code into and out of the wiki. Example:
:<lang python>print 'this line must not have leading indentation!'
:<lang python>print('this line must not have leading indentation!')
if True:
if True:
print 'example: ', foo(3), len(bar)</lang>
print('example: ', foo(3), len(bar))</lang>


Some Python examples may deviate from idiomatic Python because they may be written to work in Python 3.X as well as Python 2.X environments. This includes doing things like:
Some Python examples may deviate from idiomatic Python because they may be written to work in Python 3.X as well as Python 2.X environments. This includes doing things like: