Python Basic Syntax – Python Programming

Python Programming - Basic Syntax
Photo by Danny Meneses from Pexels

Running Python programs is very similar to Java, C, programs. Python can be run in different modes. It has different implementations like CPython, IronPython, Jython. Python Basic Syntax is very easy to learn and remember.

Python Basic Video Tutorial

Interpreter or Shell mode

For Starting python shell in command line type below command on Windows or Linux:

python

or

python3 

Note: We mostly use python3 command in Linux because there are two Python Versions installed in there. Above both commands will work but Python Version difference will be there.

It will generate output like this

Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. 
>>>   

Print Hello World in  Python

Once you start python shell in windows or ubuntu type bellow program in the terminal.

print("Hello World!!!")

How to Run Python File using Terminal

You can create file with extension  .py  and run it in the terminal:

python3 filename.py

Rules for Initialising Variables or Identifiers in Python

A python identifier starts with A to Z or a to z or an underscore( _ ) followed by zero or more letters, underscores, and digits (0 to 9).

Allowed Identifiers: A, a, _a, _A123, _123, etc.

Not Allowed Identifiers: 123, $ads, etc.

How to Comment in Python

For single line comment in Python  #  symbol and """ for multiple line is used:

# single line comment
"""
Multiple Line Comment
"""

Line and Indentation

In Python, every Line is considered a new block of code and python does not use braces instead Indentation which means Indentation is very important

if 5>2:
print('Five greater than 2')

Whats Next – Python Variables

Share