Python – First Program

In this tutorial, we will learn how to run the first python program using scripting mode. We will also discuss comments in python.

So far you have learned to install python and IDLE, to start your first program, you need to search and open IDLE in your PC. Now from python shell, select New from the File menu or press CTRL + N to open a text editor, you need to write your code here (not the Shell).

#First program to print Hello World
print("Hello World")

Now select File -> Save As or press CTRL + S to save your code. Make sure you save python file with the .py extension.

You have successfully created your python program. Finally select Run -> Run Module or press F5 to execute your first code.

print() – The print() function in python is used to display information to the users. You can print text, number, or both using print() function.

# – It makes a line as a comment in python. Actually, the line of comment is ignored by the python interpreter. Proper use of commenting in a program gives more readability. You can explain, what is going on your program using it.

Single Line Comment in Python: You can add comments to the program by typing # sign in front of each line.

#This is a comment
#Second line of comment
#Third line of comment
print("Learning Commenting in Python")

Multiple Line Comment in Python: You can write a multi-line comment using three single quotes (or three double quotes).

'''
This is a comment
Second line of comment
Third line of comment
'''
print("Using Multi-Line Comment")
53
Created on By S. Shekhar

Python - Quiz 3

1 / 4

Which of the following is used to open a new text editor in python?

2 / 4

What is the extension of a python file?

3 / 4

What all you can print using print( ) command?

4 / 4

Which of the following is used to give comments in python?

Your score is

The average score is 83%

0%