Python Syntax

In Programming world printing a Hello World! message to the screen will be the first program in a new programming language.

We can Run python program,

  1. In Interpreter prompt and,
  2. In Script file

1. Interpreter Prompt

Python comes with an interpreter that run in Command Prompt window, in this window we can try bits of python program without saving the entire program. To run python interpreter mode, Run command prompt and type “Python”. To execute the code hit enter.

C:\Users\NeuralBeast>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

In Python we can write the Hello World! program in one line, the example is given below.

Example:

>>> print("Welcome To Neural Beast's Python Tutorial")
Welcome To Neural Beast's Python Tutorial
>>>

To close interpreter prompt type exit() command and hit enter.

Python on cross-platform

Python is a cross-platform language, hence it runs on all the major Operating System.

Python on Linux

Linux operating system is mainly designed for programmers, so python is already installed on most of the Linux system. In python we need to change some few settings to start programming.

To Run python prompt, open your Terminal window, to check whether python is installed, type python and hit enter, this will open python prompt with >>> symbols.

$ python
Python 3.8.2 (default, Sep 18 2014, 22:59:38)
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

To Run python code on terminal type,

>>> print("Welcome To Neural Beast's Python Tutorial")
Welcome To Neural Beast's Python Tutorial
>>>

To close the python interpreter type exit() and hit enter.

2. Script File

In this type we can save our entire python code in a text file with the extension as .py (Eg: “hello.py“).

To run python script file, first navigate the prompt to the folder where you have saved the python script, to do that use cd command, the cd command is change directory, is used to navigate through your file in command prompt. file and simply type “python” and “name of the script file” in command prompt.

Example:

D:\python>python hello.py
Welcome to Neural Beast's Python Tutorial
D:\python>

More Reading

Post navigation

3 Comments

Leave a Reply

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