First I have to tell you about the Python interpreter. The Python language has a built in programming environment which makes testing code changes and possibilities very simple. As long as you have python in your PATH, you can open a command prompt (Windows, Mac, and Linux OS’s all have it), and type python. The output of running python is below:
$ python Python 2.7.6 (default, Mar 22 2014, 22:59:38) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>>
Continuing my harp on the cleanliness of Python, the Hello World example is very simple.
>>> print 'Hello codecrawl.com World' Hello codecrawl.com World >>>
That’s it, the print function in Python 2.7 and lower looks like this and prints output to the console. There are also many ways to format output and make it more readable if you happen to need to print variables along with static text.
>>> first_name = 'First' >>> last_name = 'Last' >>> >>> print 'Hello %s %s. Welcome to codecrawl.com!' % (first_name, last_name) Hello First Last. Welcome to codecrawl.com! >>>
first_name and last_name are variables which can get their data from the developer or from user input. Either way, you can use print to display a static message with dynamic data from variables. There are many different possibilities.
We’ll discuss more about variables in future posts, but this was your gentle introduction into the world of Python.