First Python program


Python provides us 2 ways to get the code executed

  • Using Interactive Interpreter Prompt
  • Using a Script file

INTERACTIVE INTERPRETER PROMPT

    It is also known as Python Interpreter or Python Shell. It is a quick way to execute the commands. It does not need any save file to run or test the code. It has auto-completion, built-in functions, command history, which helps a programmer explore the Python program. It can copy and paste the code. By setting the environment, we can launch the python modules that have been installed in the system.

    $ cd environments

    $ . my_env/bin/activate

Working with Interactive Interpreter

Prefix “>>>” accepts the python syntax.
E.g., >>> print(“Hello World”)

Hello World

Prefix “…” accepts the multiple line code in the interpreter. To break this multiple line code command, you need to press Enter twice.

Image Not Found

Script File

Python is a high-level programming language. Python script contains codes that are written in Python Language. The extension of the file is “.py.” To run a script, you need a python interpreter.

Ways to run the Python Script:-

  • 1. Interactive Mode
    Run the program line by line (interpreter) in Command Prompt.
  • 2. Command Line Mode
    Saving a file with extension .py, and you can run in command prompt.
  • 3. Text Editors (like VS Code, etc.)
    You need a code runner and Python installed in your system to run the text editor.
  • 4. IDE (like PyCharm)
    Integrated Development Environment is the full form for the IDE; it contains all the prerequisites required to run a code.

In this way each statement can be executed

CODE

print(“good morning”)

OUTPUT

Image Not Found

USING SCRIPT FILE

The interactive interpreter prompt helps us when we are eager to know the output of individual statements of the code. We cannot write the code every time on the terminal because of each line execution. We need to write the whole code into our file which can or might be executed later.
For this purpose, we need to open an editor like notepad, create a file named first.py (Python used .py extension), and write the following code in it.

CODE

print (“ Hi , I am new to Python”)

NOTE:- To run this code,this file is named as filename.py,after which we need to write py filename.py on the command prompt for the output.

OUTPUT

Image Not Found