PyLearn / Printing a line



Welcome to PyLearn once again! In this tutorial I will teach you how to output a line in Python. In the previous tutorial I had already given three programs in:


  1. C++

  2. Java

  3. Python


You had also seen that the syntax of Python is quite simpler than others in the market and also seen in kind of work the incredible power of Python is harnessed. Before we go any further please:

  1. Install python on your computer from here. Find the download suitable for your OS from the Python download page. It’s best to download the latest version.

  2. After downloading the file open it by double-clicking it.

  3. A window will appear. Select the checkbox which says “Add Python X.X(This the version name of your Python installation) to PATH”. This will add the path of your Python installation to your path environment variable, making it easier for installing Python modules on your computer.

  4. Click “Install Now”.

  5. If you are asked, if you want to allow the program to make changes to your system, click “Allow”.

  6. The Python will be installed on your system in a few minutes. When finished, click “Close” to close the window. You can now start using Python. You can just open up Python X.X IDLE to start writing your code given in this and the succeeding tutorials.


Now suppose you are building a game in Python. Someone is playing the same and he loses. Now you want to display a “Game Over!” on the screen. What will you do to print this message over the screen? Here’s when the Python print statement comes in handy. The print statement in Python is used to print strings(characters), integers and float(in other words decimals) on ht e computer screen. An example of the print statement is given as follows:


print (“Hello, World!”)


Output: Hello, World!


Here you can the see that we first type in ‘print’ following that in a parentheses we give double quotes and type the statement we want to print. Here it is important to note that instead of the double quotes, we could have also given single quotes, even then the output will remain the same. It is also important to note that whenever you enter characters you also require to give the quotations, or you will run into an error. If the line you want to print is just numbers or perform some calculations you have to omit the quotations otherwise it will just print what you typed within the quotations. For example, the program print (5+3) will print 8 as an output. But if type print (“5+3”) or print (‘5+3’) it will print just 5+3 as an output.


In the next lesson I would explain how to perform calculations like addition and subtraction in Python. Thanks!


Next Lesson: