Skip to main content

Python basics

Python is most popular among all programming languages recently . It is because of the huge functionalities and library inside this language .

Python was invented by Guido van Russel during his vacations as a new project to create an interpreter . The syntex and procedure he used while creating this interpreter is called python later .
Python 3 is the suitable version to all . We all just need to download and install the python package to execute the python scripts on computer .

Python is platform independent can be run on all operating systems , just need to install python package .

Python has an interpreter to execute the scripts and command line for the user interface but command line only executes on command at a time and not a entire script .we can install other IDE like Jupyter to execute the entire python script .

Python syntax is very easy and short because of huse library support that makes it most popular .

Pyhon scripts have the .py extention while saving .

How to Run Python code or scripts - 

1. At First , need to download the Pyhon package from  and install .

2. To check the python is installed or not , write below command in cmd shows python version number -
     python --version

3. If python installed then we can execute python environment in CMD by using below command - 

4. Now we can run python code .

5. To execute any python script "" with CMD , set the directory where file is kept and use the below command -

We can see the python basic syntex -

1.  Print("Hello")

2. Basically python is for data science and working with the large databases so it uses the concepts of List and Dictionary .

List - we can create a list of elements or an empty list can can be fill as need .

food = ["Orange" , "Mango" , "Pineapple" , "Strawberry"]

or we can keep it empty and can append when need .

food = [ ]
These elements are on index starting from 0 . 

Dictionary - This concept is based on the "Key" and " Value " for a dataset . Dictionary syntex is same as List but it uses curly brackets .

record = { }
record["jack"] = 120
record ["ram"] = 121

3. Variables - we can assign the values to variable and variables follow the simillar syntex as c and java .

-> variables only can start with letters or underscore .
-> variables can not start with numbers but can be with Alphanumeric and underscore combination .

4. Mathematics Operators -
All math operators are similar as other high level programming languages but exponent operator is a new one .

=  Assignment
+  Addition
-  Subtraction
/  Division
* Multiplication
** Exponential
==  Comparison
<  Less than
> Greater than
<=  Less than or equal to
>=  Greater than or equal to

5. File operations -

fopen()  - To open any file .
read() - To read a file opened in Read mode .
split() - To split any list or opened file from a character like new line (\n) or comma .

if we saved a file -

f = open("")
data =
splitted = data.split( '\n' )

6. Loops -
Python follows very easy to write syntex for loops . After the for loop statement , colon ( : ) and then Indentation is must befor loop body .

for n in List_name :
(4 white spaces)  Body of loop

7. Indentation - It is the most important in python . After any for loop , if , else statements etc we need to end statement with a colon ( : ) and to write the body a particular Indentation is must otherwise it will throw an error . Indentation just means a Tab space or 4 white spaces .

8. Conditional statement -
If , else are the conditional statements . We need to write a condition after " if " keyword , then a colon ( : ) and then give indentation to new line and write body from new line .
Conditinal statements can be used inside loop statements and vice versa .

x = 10 
y = 20 
if ( y>x) :
(Indent) print("It will return True")
else :
(Indent) print("It will return False")