Today in this tutorial we will write and execute our first program in Python.
Write and execute your first python program using terminal
Follow the given steps to write and execute the hello world program using the terminal –
ctrl+alt+t to open the terminal on your system
2. Create a directory where you want to create python files by using mkdir command –
For example –
3. Move to created directory using –
4. Create and open hello.py with a text editor –
Please note that the .py extension is important. Now add the given line to this file
print ("Hello World!")
Where print() is a built-in python function Hello World is a string that can be enclosed using single or double-quotes. We will see functions and strings in Python in detail in the coming articles.
ctrl+s to save and then
ctrl+x to exit from the text editor.
5. Execute the program using the python (In windows) or Python3 (In Linux or Mac)command –
or use –
This will display the output as given in the image below –
Create hello world program in Visual studio code
1. Create a directory lets say python_dir in your current working directory –
2. Right-click on the python_dir and open it with visual studio code.
3. Next create a file with the name hello.py write the given line in this file
ctrl+s to save this file.
4. Click on run this file by clicking on the green triangular icon given on the upper right side of the editor.
This will display the output on the terminal inside the IDE.
Now try this on your own system. If face any problem then write us in the comments below.