Wednesday, March 30, 2016

Hello World! (console printing and executable)

Of course the first post of a blog about programming in Python have to be hello world in Python :)
This is the file
#!/usr/bin/env python
print "Hello World"
to execute this file
Two elements of the script. First, the command print, this command write to the standard output the parameters given. These parameters can be variables, objects (as we are going to discuss in a later post), or as in this case constants. The second element is the first line starting with the charcarter '#'. In Python every character in a line after the symbol '#' is considered as a comment (python interpreter will ignore this). Particularly in our example we have the following comment
#!/usr/bin/env python
This comment is not mandatory, however, it is used if we want to run as an standalone executable. First, we can give execution rights to the file using chmod
$chmod +x 
From now on, we only have to type,
to execute the

No comments:

Post a Comment