Python-Ref > Basic usage > Hello World > Hello World 2
 
 

<-^^
Klíčová slova
Moduly
Knihovní funkce

Hello World 2

This example takes the simple 'Hello World' example a little bit further.
We start from the simplest version of 'Hello world'.
Expand/Shrink
Zdroj: (hello1.py)
  1   print "Hello World!"
stdout:
Hello World!
Doba běhu: 15.0 ms
In the following snippet we store the text to be printed in a variable. The '#' character is used for comments - anything from this character to the end of the line is ignored.
Expand/Shrink
Zdroj: (hello2.py)
  1   text = "Hello World!"  # at first we store the text in a variable called 'text'
  2   print text             # then we print it on the terminal
stdout:
Hello World!
Doba běhu: 13.8 ms
Now lets make the text a little prettier in the way of Hyman Kaplan. For this we use a simple iteration using the for-loop.
Expand/Shrink
Zdroj: (hello3.py)
  1   text = "Hello World!"  # at first we store the text in a variable called 'text'
  2   for ch in text:        # we take each letter of the text string and put it into the variable 'ch'
  3       print ch, "*",     # we use indentation to tell the interpreter which code is inside the for-loop
  4                          # the comma (,) either separates the arguments to the print command or prevents
  5                          # creation of the new line (in case it is not followed by an argument)
  6   
stdout:
H * e * l * l * o *   * W * o * r * l * d * ! *
Doba běhu: 14.1 ms