Monday, 18 May 2026

What is Python, History of Python, Advantages, Features, Applications and who should learn Python

 What is Python?

  • Python is a General Purpose Programming Language
  • Python is a High Level Programming Language
  • Python is a Multi-Paradigm
  • Python support Both Interactive and Batch Mode Execution

(or)

👉 Python is a General Purpose,High Level,Interpreted,Interactive,Modular,Dynamically Typed,Garbage        Collected,Procedure Oriented,Object Oriented and Scripting Programming Language.

History of Python:

  • Python Was Developed by the "Guido Van Rossum" in the year of 1991(Actually this Project Implementation his started in early of 1980's i.e., Dec-1989).
  • The Name Python was derived from the "Guido Van Rossum" favorite TV Fun show "the complete Monty python's flying circus".
  • He is a Dutch Programmer, best known as a Creator of the Python Programming Language i.e., he is Father of Python Programming Language.
  • Currently He is working in Microsoft.
  • the python programming language implementation his influenced by majorly 2 programming languages, they are
    ðŸ‘‰ABC
    ðŸ‘‰Modula3

Advantages of Python:

1).Simple Syntax
in python, there's no concept of ;,{},()
python always follow the "Space Indentation" concept

ex: if block representation
---
C/C++/Java/.Net Python
--------------- ----------
if(condition) if condition:
        { stmt_1
           stmt_1; stmt_2
             stmt_2; ......
   ...... stmt_n
stmt_n;
}

2).Less Code

Python programs having Less code when compared to other programming languages programs code like C,C++,Java,.Net,Go,...

ex:
---
write a C program to print "hello world!"?

demo.c
------
#include<stdio.h>
void main()
{
   printf("hello world!");
}

write a Java program to print "hello world!"?

demo.java
---------
import java.io.*;
class Test
{
   public static void main(String[] args)
   {
       System.out.println("hello world!");
    }
}

write a Python program to print "hello world!"?

demo.py
-------
print("hello world!")

3).Dynamically Typed Language

ex:
---
write a C program(Static Typed Language) to perform the addition operation on two different types of numerical values?

demo.c
-------
#include<stdio.h>
void main()
{
   int x=10;
   float y=2.3;
   float z=x+y;
   printf("%f",z);
}

write a Python program(Dynamically Typed Language) to perform the addition operation on two different types of numerical values?

demo.py
-------
x=10
y=2.3
z=x+y
print(z)

4).Python Provides N no.of Builtin Libraries/Packages/Modules

Features of Python:

1).Easy-To-Learn
2).Easy-To-Read
3).Easy-To-Use
4).Easy-To-Maintain
5).Portable
6).Cross-Platform
7).Secure
8).Scalable
9).Extendable
10).Flexible
11).Robust
12).Versatile
13).Strongly Typed Language
14).Garbage Collected Language
15).Interpreted Language
16).it support Multi-Threading and Multi-Processing
17).it support all type of database connections
18).Free and Open-Source

Note:
-----
Python is Completely Free and Open-Source Project,it is maintained by PSF(Python Software Foundation) Team.

www.python.org --> Python Official Website

What we Can do With Python?

1).Robotic Process Automation(RPA)
2).Artificial Intelligence(AI)
3).Data Science
4).Data Analytics
5).Data Engineering
6).Big-Data
7).Web Application Development
8).GUI Application Development
9).ERP Application Development
10).GIS Application Development
11).Mobile Application Development
12).Networking Application Development
13).Scientific Application Development
14).Animations
15).Automation Testing
16).Networking Automation
17).Cloud Computing
18).Quantom Computing
19).IOT
20).DevOps
21).DevSecOps
22).MLOps
23).FinOps
24).AiOps
25).Cyber Security
26).Blockchain
27).Admin Activities(DBA,Sys Admin,N/W Admin,OS Admin)
28).Gen AI & Agentic AI
29).Web Scrapping
30).Medical & Healthcare System's


who should learn Python?

Students
Graduates/Freshers
Career Switchers(from Non-IT to IT)
Data Professionals(Data Scientists, Data Analysts, Data Engineers, Big Data Engineers)
Developers
Test Engineers/QA Engineers
DevOps Engineers
IOT Engineers
Cloud Engineers
AI/ML Engineers
RPA Developers
Gen AI Developers
Network Engineers
Cyber Security Professionals

Wednesday, 30 May 2018

To print the multiplication Table

Example:

num=int(input("enter number: "))
print("the multiplication table of %d"%num)
for i in range(1,11):    
        print(num,'*',i,'=',num*i)


output:
enter number: 5
the multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45

5 * 10 = 50

Friday, 23 February 2018

command line arguments in python




  • the concept of passing the arguments from command line at the time of running the python program/file,that type of arguments are called command-line arguments.
  • file name also taken as a one of the command line argument.
  • all the command line arguments are stored into list object in the form of strings, that list object stored into the "argv" variable of sys module.

Example:

import sys
print(sys.argv)
print(len(sys.argv))
for p in sys.argv:
    print(p)


Output1:

C:\Desktop>python commandlineargument.py hai siva krishna

['commandlineargument.py', 'hai', 'siva', 'krishna']
4
commandlineargument.py
hai
siva
krishna

Output2:

C:\Desktop>python commandlineargument.py arg1 arg2 arg3

['commandlineargument.py', 'arg1', 'arg2', 'arg3']
4
commandlineargument.py
arg1
arg2
arg3

Example:

import sys
if len(sys.argv)==3:
    try:
        x=int(sys.argv[1])
        y=int(sys.argv[2])
        z=x+y
        print(z)
    except(ValueError):
        print("enter numerical values only")
else:
    print("enter two userdefined arguments only")

Output1:
C:\Desktop>python commandlineargument.py 4 5

9

Output2:
C:\Desktop>python commandlineargument1.py 4

enter two userdefined arguments only

Output3:
C:\Desktop>python commandlineargument1.py 4 abc

enter numerical values only


Thursday, 22 February 2018

reduce function in python

reduce( ) support only python 2.x

reduce( ) doesn't support python 3.x

Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value. 

For example, 
reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) 

calculates ((((1+2)+3)+4)+5). 

The left argument - x is the accumulated value and the right argument - y is the update value from the iterable object.

x=[2,4,5,6,3]
y=reduce(lambda i,j:i+j,x)

print(y)

20

Tuesday, 9 January 2018

difference between is and == in python

"is" vs "=="
-------------------------
  • "is" expressions evaluate to True if two variables point to the same object.
  • "==" evaluates to True if the objects referred to by the variables are equal.
>>> a = [1, 2, 3]
>>> b = a >>> a is b
True
>>> a == b
True >>> c = list(a) >>> a == c
True
>>> a is c
False

Switch case implementation in python

Example:

def calculator(operator, x, y):
    if operator == 'add':
        return x + y
    elif operator == 'sub':
        return x - y
    elif operator == 'mul':
        return x * y
    elif operator == 'div':
        return x / y
    else:
        return None

print(calculator('add',2,3))
print(calculator('div',6,2))
print(calculator('mod',4,2))

Output:

5
3.0

None


Example: by using dict

def calculator(operator, x, y):
    return {
        'add': lambda: x + y,
        'sub': lambda: x - y,
        'mul': lambda: x * y,
        'div': lambda: x / y,
    }.get(operator, lambda: None)()

print(calculator('add',2,3))
print(calculator('div',6,2))

print(calculator('mod',4,2))


Output:

5
3.0
None

Thursday, 4 January 2018

About Python





  • Python is powerful and faster execution
  • Python plays well with others
  • Python runs everywhere 
  • Python is friendly & easy to learn
  • Python is a Open source. 

Monday, 27 November 2017

converting word to number in python


pip install word2number


from word2number import w2n
print(w2n.word_to_num('ten'))
10
print(w2n.word_to_num('one hundred twenty three'))
123
print(w2n.word_to_num('one thousand two hundred twenty three'))
1223

convert number to word in python




pip install n2w

import n2w

print(n2w.convert(12))

'twelve'

print(n2w.convert(123))

'one hundred twenty three'

Tuesday, 14 November 2017

underscores _ in Python

Understanding the underscore( _ ) of Python :

The underscore ( _ ) is special in Python.

There are 5 cases for using the underscore in Python.

  • For storing the value of last expression in interpreter.
  • For ignoring the specific values. (so-called “I don’t care”)
  • To give special meanings and functions to name of variables or functions.
  • To use as ‘Internationalization(i18n)’ or ‘Localization(l10n)’ functions.
  • To separate the digits of number literal value.


When used in interpreter :

  • The python interpreter stores the last expression value to the special variable called ‘_’.


Example:

>>> x=10

>>> x

10

>>> _

10

>>> _*2

20

>>> _

20

>>> _+3

23

>>> _

23

>>> y=_/3

>>> y

7.666666666666667


For Ignoring the values:


  • The underscore is also used for ignoring the specific values. 
  • If you don’t need the specific values or the values are not used, just assign the values to underscore.


Example:

Ignore a value when unpacking:

>>> x, _, y = (1, 2, 3)

>>> x

1

>>> y

3

>>> 

Ignore the multiple values:


  • Note:which is available in only Python 3.x.


>>> x, *_, y = (1, 2, 3, 4, 5)

>>> x

1

>>> y

5

>>> 

Ignore the index:

for _ in range(10):

print("hai")

hai

hai

hai

hai

hai

hai

hai

hai

hai

hai

def do_something( ):

print("hello")

for _ in range(10):

do_something()

hello

hello

hello

hello

hello

hello

hello

hello

hello

hello

Ignore a value of specific location:

>>> x=(5,10,15,20,25)

>>> for _,val in x:

do_something()



Give special meanings to name of variables and functions:

  • The underscore may be most used in ‘naming’.
  • The PEP8 which is Python convention guideline introduces the following 4 naming cases.


single underscore( _ ):

  • leading underscore( _ )

example:

_variablename or _functionname or _methodname or _classname


  • This convention is used for declaring protected variables, functions, methods and classes in a module.



  • tailing underscore( _ )

example:

variablename_ or functionname_ or methodname_ or classname_


  • This convention could be used for avoiding conflict with Python keywords or built-ins.


Tkinter.Toplevel(master, class_='ClassName')
# Avoid conflict with 'class' keyword

list_ = List.objects.get(1)
# Avoid conflict with 'list' built-in type


double underscore( _ _ ):


  • leading double underscore(_ _)

example:
 _ _varaiblename or _ _functionname or _ _methodname or _ _classname


  • double underscore will mangle the attribute names of a class to avoide the conflicts of attribute names between classes.
  • (so-called “mangling” that means that the compiler or interpreter modify the variables or function names with some rules, not use as it is). 
  • The mangling rule of Python is adding the “_ClassName” to front of attribute names are declared with double underscore. 
  • That is, if you write method named “__method” in a class, the name will be mangled in “_ClassName__method” form.



  • leading and tailing double underscores(_ _)

example:
_ _variablename_ _ or _ _functionname_ _ or _ _classname_ _ or __methodname__



  • This convention is used for special variables or methods (so-called “magic method”) such as   _ _init_ _  ,  _ _len__  ,          _ _new_ _ ,_ _del_ _,......etc.
  • These methods provides special syntactic features or does special things.


example:
class A:
    def __init__(self, a):
          self.a = a
    def __custom__(self):
               pass


As Internationalization(i18n)/Localization(l10 n) functions :


  • The built-in library gettext which is for i18n/l10n uses this convention, and Django which is Python web framework supports i18n/l10n also introduces and uses this convention.


# see official docs : https://docs.python.org/3/library/gettext.html import gettext
gettext.bindtextdomain('myapplication','/path/to/my/language /directory') gettext.textdomain('myapplication') _ = gettext.gettext
# ...
print(_('This is a translatable string.'))



To separate the digits of number literal value:

  • This feature was added in Python 3.6. It is used for separating digits of numbers using underscore for readability.


>>> x=1_00

>>> x

100

>>> y="siva_krishna"

>>> y

'siva_krishna'

>>> z=0b_101

>>> bin(z)

'0b101'
>>> 

Friday, 3 November 2017

manual debugging in python

python debugging


import  pdb

for i in range(0,10):

            x=i*3

           print(i,x)

           pdb.set_trace()

Note:

n  means next

c  means continue

x  print current x value

i  print current i value


output:

0 0

> d:\siva krishna\python_practice\python tricks\debuggin.py(3)<module>()

-> for i in range(0,10):

(Pdb) i

0

(Pdb) x

0
(Pdb) c

1 3

> d:\siva krishna\python_practice\python tricks\debuggin.py(3)<module>()

-> for i in range(0,10):

(Pdb) i

1

(Pdb) x

3

(Pdb) c

2 6

> d:\siva krishna\python_practice\python tricks\debuggin.py(3)<module>()

-> for i in range(0,10):

(Pdb) i

2

(Pdb) x

6

(Pdb) n

> d:\siva krishna\python_practice\python tricks\debuggin.py(4)<module>()

-> x=i*3

(Pdb) c

3 9

> d:\siva krishna\python_practice\python tricks\debuggin.py(3)<module>()

-> for i in range(0,10):

(Pdb) i

3

(Pdb) x

9


(Pdb) 

Thursday, 2 November 2017

clear the python command window screen



how to clear the python command window screen


C:\Users\siva>python

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (
Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> print("hai siva")
hai siva
>>> print("welcome to my blog")
welcome to my blog
>>> x=10
>>> y=20
>>> z=x+y
>>> z
30
>>> import  os
>>> def  cls( ):
...     os.system("CLS")
...
>>> cls( )

>>>

Tuesday, 31 October 2017

Sending email with python

  • sending email with python, first we need to install module called smtplib
  • in latest versions of python smtplib module is builtin



import smtplib
host="smtp.gmail.com"
port=587
username="abc@gmail.com"
password="*********"
from_email=username
to_list=["xyz@gmail.com","abc@gmail.com"]
email_conn=smtplib.SMTP(host,port)
email_conn.ehlo()
email_conn.starttls()
email_conn.login(username,password)
email_conn.sendmail(from_email,to_list,
                    "hello,good morning")
print("mail successfully send")
email_conn.quit()

Tuesday, 10 October 2017

Pass by value and Pass by reference in python

Pass by value (call by value) and Pass by reference (call by reference) :



Pass by value (call by value):


  •  Original value is not modified in call by value.
  •  In call by value, value being passed to the function is locally stored by the function parameter in stack memory location. 
  •  If you change the value of function parameter, it is changed for the current function only.
Example:


a=10

def f1(x):

    print(x)

    x=20

    print(x)

f1(a)

print(a)

Output:

10

20

10



pass by reference (call by reference):

  • In call by reference, original value is modified because we pass reference (address).
  • Here, address of the value is passed in the function, so actual and formal arguments shares the same address space. 
  • value changed inside the function, is reflected inside as well as outside the function.
Example:


b=[1,2,3]

def f2(y):

    print(y)

    y[0]=10

    y[1]=20

    print(y)

f2(b)

print(b)

Output:

[1, 2, 3]

[10, 20, 3]

[10, 20, 3]

Monday, 25 September 2017

The concept of if _ _name_ _ = = '_ _main_ _ condition

The concept of      if _ _name_ _ = =  '_ _main_ _ ' :

Example:  addition.py

def  add(x,y):

     z=x+y

     print(z)


add(4,5)

Output:

9

Example: adding.py

from addition import add


add(2,3)

Output:

9

5

Note:

  • here executing both main module and sub module add function.
  • in these cases we don't want execute imported module add function(sub module add function). 
  • i want execute only main module add function.
in this situation we are using   if  _ _name_ _ = = '_ _main_ _' :


Example:


def add(x,y):


    z=x+y

    print(z)

if __name__= = '__main__':

    add(4,5)

Example:

from addition import add


add(2,3)


Output:

5


Access modifiers in Python

Access modifiers in Python :

In C++ and Java, things are pretty straight-forward. There are 3 magical and easy to remember access modifiers, that will do the job (public, protected and private). 

But there’s no such a thing in Python. That might be a little confusing at first, but it’s possible too.

Public:

All member variables and methods are public by default in Python. So when you want to make your member public, you just do nothing.

Protected:

Protected member is (in C++ and Java) accessible only from within the class and it’s sub classes.

How to accomplish this in Python? 

The answer is _ by convention. By prefixing the name of your member with a single underscore, you’re telling others “don’t touch this, unless you’re a subclass”.

  • This changes virtually nothing, you’ll still be able to access the variable from outside the class, only if you see something like this.
  • you explain politely to the person responsible for this, that the variable is protected and he should not access it or even worse, change it from outside the class.

Private:

By declaring your data member private you mean, that nobody should be able to access it from outside the class, i.e. strong you can’t touch this policy. 

Python supports a technique called name mangling. This feature turns every member name prefixed with at least two underscores and suffixed with at most one underscore into 

_<className>_ _<memberName>  ------> Name Mangling


Example:

class test:
    def  __init__(self): #constructor
        self.x=10  #public

        self._y=20  #protected

        self.__z=30  #private

    def  m1(self): #method
        print(self.x)
 
        print(self._y) 

        print(self.__z) 
    
t1=test( )

t1.m1( )

print(t1.x)

print(t1._y)

print(t1._test__z)

print(dir(t1))

Output:

10

20

30

10

20

30

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_test__z', '_y', 'm1', 'x']


Tuesday, 19 September 2017

How to check whether number is prime number or not



Prime Number:
Any number divisible by 1 and itself that number is called prime number.

Example:

num = int(input("enter number: "))
if num > 1:
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break
   else:
       print(num,"is a prime number")
       

else:
   print(num,"is not a prime number")


Output:

enter number: 5
5 is a prime number

Output:

enter number: 12
12 is not a prime number
2 times 6 is 12

Output:

enter number: 15
15 is not a prime number
3 times 5 is 15

Monday, 18 September 2017

how to calculate Age


write a program to calculate age in python:

import  datetime
year=datetime.datetime.now().year
year_of_birth=int(input("enter your birth year: "))
print("you are %i years old!"%(year-year_of_birth))

Output:

enter your birth year: 1991
you are 26 years old!