Difference between revisions of "Python:Hello World"

From Progzoo
Jump to: navigation, search
Line 1: Line 1:
 
 
{{topTenTips}}
 
{{topTenTips}}
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="py" className="Hello"><p>
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="py" className="Hello"><p>
 
The number one program is <b>Hello World</b>.
 
The number one program is <b>Hello World</b>.
 
This program prints the string "Hello World".
 
This program prints the string "Hello World".
 +
 
</p><prog>
 
</p><prog>
 
print "Hello world"
 
print "Hello world"
 
</prog></question>
 
</prog></question>
 +
 +
Caution: The above code is only valid for Python 2.x. In Python 3.x, <code>print</code> has become a function and it is necessary to enclose the argument in parentheses:
 +
<pre>
 +
print("Hello world")
 +
</pre>
 +
This version of the code will also work on 2.x, in the case when there is only one argument.

Revision as of 06:13, 21 November 2009

The number one program is Hello World. This program prints the string "Hello World".

[Font] [Default] [Show] [Resize] [History] [Profile]

Caution: The above code is only valid for Python 2.x. In Python 3.x, print has become a function and it is necessary to enclose the argument in parentheses:

print("Hello world")

This version of the code will also work on 2.x, in the case when there is only one argument.