Your first python program

We hope you installed python in your PC and you are ready to start your programming journey now.
In this tutorial, we are using notepad as our editor to write the python code.
After writing, we are using the python interpreter to execute/run our program.

What is interpreter?

An interpreter is a program that takes part of reading all of the source code from a file that we wrote using an editor.
It will read our code one line at a time. and evaluates every character of the code for correct syntax in our coding!
After the interpreter finished entire code evaluation, It will conversate to the compiler to compile entire code.

What is compiler?

A compiler is also a program. Since electronic devices only understand binary data/instructions, It takes the job of converting the human written code into binary instructions. After interpreter reads every line in the code and if it founds all code is syntactically correct, It will then informs to the compiler and the compiler will start the conversion. Let us see how we can utilize these 2 tools for our python program.

Writing your first python code

Before writing the python code, open notepad, make sure there are no text contents, set your screen reader symbol level to “all” to speak out each and every character in the file.
Within the first line, write the following code:
print("Hello world!")

Saving your python program

After writing the code, press ctrl+s to open save as dialog box. If you saving for the first time, the dialog box will open, else the file will be saved using previous saving settings.
After the save as dialog opens, follow below steps:

  1. Type the name of the file along with the .py format at the end of the file.
  2. Press tab key and in the save as type combo box, choose all files.
  3. Choose the location where you want to save the file and activate save button.

Explanation of the code

the line
print("Hello world!")
Instructs python to output the text called “Hello world!” on the screen.
print is a function in python that have the capacity of displaying the given text contents. The contents is usually written within the brackets and quotation mark.
Like print, there are various functions in python, that is used for various purpose.
After function does its job, It may return any data and we can use that data for any purpose.
We will learn deeply about functions in later tutorials.

Running our python program

After we write our program and if we want to run our program, in most of the programming languages, we should compile the program into machine language from the human readable language. But, in python, Its not like that. We can skip the compilation step and we can just run the program using the python interpreter. Compilation is optional in python.

Running our python program through command prompt

To run the python program through command prompt, follow below steps:

  1. In file explorer, Navigate to the directory where you stored your file of source code,
  2. Press alt+d to navigate to the address bar, Clear all text in the address bar, type “cmd” without quotation mark to open command prompt and press enter,
  3. After command prompt window opens, type python “your file name.py” to run your python program,
  4. Optional: If command prompt gives output like “python is not recognized as an internal or external command, operable program or batch file.”, type c:\windows\py.exe “your file name.py” to run python program alternatively,
  5. To listen the output of the program, use the NVDA review text commands.

Compiling python program

If you don’t want to see your code by others or if you want to use code of existing file in another file, you will compile the python code. For compiling, follow the steps of running python code and while you are in command prompt, type python -m “Your file name.py” in the command prompt.
A new .pyc extension file will be generated inside the __pycache__ directory. That file will be the compiled python file.

Published by Harsha HD

Myself Harsha, I'm a person from Bangalore, Karnataka with 100% visually challenged. I completed my PG in masters of computer application at Bangalore university in the year 2022. With my coding interest along with interest of sharing those knowledge to our visually challenged community, I founded this website, trying to provide accessible coding materials and training specially for visually challenged people with affordable cost. So, that the VI people will able to perceive their education in technical/electronics stream in an accessible way.

Leave a Reply

Your email address will not be published. Required fields are marked *