INTRODUCTION TO PYTHON
Python is a simple and general purpose, high-level and object oriented
programming language/multipurpose language, interrupter language.
Guido Van Rossum – Father/Founder of python at 1991 (1985-1990
at Netherlands).
Python is easy to learn yet powerful and versatile scripting language,
which make it attractive for application development.
NAME OF PYTHON
Guido Van Rossum was a fan of the popular BBC comedy show of that
time, “monty pythons flying circus”. So he decided to pick python for his
newly created programming language.
WHY PEOPLE USE PYTHON
1. Software quality
2. Developer productivity- type less, less to debug, less to maintain
3. Program portability-run on diff platforms (.py) (Linux, Unix ,windows,
Macintosh or any other OS)
4. Support libraries (data scientist, cloud computing, Iot, networking, ethical
hacking data mining, artificial intelligence, etc)
5. Easy to learn
WHO USES PYTHON TODAY?
Google-web search engine(big GUI apps)
You tube-video sharing
Drop box-(cloud storage)-storage space
Electronics-Raspberry pi(company)- projects
Eve online- big game company-multiplier games
Bittorrent – which file we need go and download
Animation company -industrial light and magic
Google app engine
Maya 3d softwares
NASA website
Netflix
Intel, Cisco,HP,Seagate,Qualcom,IBMpython-software companies need
for hardware testing purposes
WHERE IS PYTHON USING?
Data science
Date mining
Desktop applications
Console based applications
Mobile applications
Software development
Artificial intelligence
Web apps
3d cad applications
Speech recognitions
Computer vision or image processing apps
Machine learning
APPLICATIONS OF PYTHON:
Software development-apps and websites
System programming-developing utilities, bug with os services
Create the GUI apps-notepad, WordPad(desktop apps)
Internet scripting-develop server and client relation- CGI(common
gateway interface)
Database programs-mysql, mssql, postgresql,sqllite
Data science
Machine learning
Serial port comms-linux and windows machine
Image processing-python
Control the robots
Natural language processing
Excel and spread sheet
file related operations
Area data mining
PYTHON FRAMEWORKS AND LIBRARIES OF POPULAR THINGS:
WEB DEVELOPMENT (SERVER SIDE)-Django, Flask, Pyramid,
CherryPy
GUI BASED APPS-Tk, PyGTK, PyQt, PyJs.
MACHINE LEARNING-Tensorflow ,Pytouch,Matplotlib,Scipy.
MATHEMATICS- Numpy, Pandas, etc.
o TensorFlow - It is an artificial intelligence library which allows us to
create large scale AI based projects.
o Django - It is an open source framework that allows us to develop web
applications. It is easy, flexible, and simple to manage.
o Flask - It is also an open source web framework. It is used to develop
lightweight web applications.
o Pandas - It is a Python library which is used to perform scientific
computations.
o Keras - It is an open source library, which is used to work around the
neural network.
o Django and Pyramid framework(Use for heavy applications)
o Flask and Bottle (Micro-framework)
o Plone and Django CMS (Advance Content management)
PYTHON PROGRAMMING
THERE IS NO COMPILATION PROCESS(ONLY
INTEREPRETATION)
THERE IS NO USE BRACES{}
THERE IS NO SYNTATX ALSO
ONLY SOURCE CODE CONVERTED TO MACHINE CODE
DEBUGGING FAST
DOWNLOADING PYTHON SOFTWARE
Step1: go to [Link] website
Step2: click on downloads
Step3: click and choose platforms
Step4: choose the current version is 3.7.1
(Version 2 and 3-2 is old version and 3 is the new version developed in 2010)
Step5: click and choose the version
Step6: double click and choose execution file and install it.
Step 7: choose 2 options mandatory to install the processor
[Link] launcher for all users
[Link] python 3.7 to path
Step 8: click and choose these above two options and click install now
Step9. Click next and next-gets finally installed in this system of windows
step10: now it’s getting downloaded and forms a two modes of operation
[Link] mode (idle 3.7.1. (64bit))-editor and save the file as .py
extension
2. Shell mode (python 32 bit)-just like command prompt-doesn’t save
anything.
SYNTAX:
def func():
statement1
statement2
……..
……..
statement N
There is no curly braces or semicolon in this programming. It is English
like language.
But python uses indentation to define a block of code. Indentation is
nothing but adding WHITESPACE before the statement(4 white spaces) when it
is needed.
DIFFERENCE BETWEEN JAVA AND PYTHON CODING:
Java program:
Public class Helloworld
Public static void main(string[] args)
[Link] (“hello world”);
Python program:
print (“hello world”)
PYTHON OBJECT TYPES (DATA TYPES)
o Programs are composed of MODULES.
o Modules contain Statements.
o Statements contain expression.
o Expression create and process the objects.
OBJECT TYPES (BUILT-IN-TYPES IN PYTHON)
1. Numbers
2. Strings
3. Lists
4. Dictionary
5. Tuple
6. Sets
7. Boolean
8. Program unit types- functions, modules, classes and objects.
[Link]
To perform some basic arithmetic and logical operation. Use this
numbers concept in python.
EXAMPLE
>>> 10+20
30
>>> 20-19
>>> 4/2
2.0
>>> 4//2
>>> 2*8
16
>>> 2**8
256
>>> 0b01001010
74
>>> 0o166
118
>>> a=10
>>>a
10
>>> a=000000000000000000000000000000000
>>>a
>>>type(a)
<class 'int'>
>>> b='suryakumar is beauty and hardworker and always support to everyone'
>>>b
'suryakumar is beauty and hardworker and always support to eveyone'
>>>type(b)
<class 'str'>
>>> 10e-4
0.001
>>> c=10e-4
>>>c
0.001
>>>type(c)
<class 'float'>
>>> w=1+2j
>>> u=1+3j
>>>w+u
(2+5j)
>>>w-u
-1j
>>> h=1+2.8
>>>h
3.8
>>>type(h)
<class 'float'>
>>>int(h)
>>>float(3)
3.0
>>>num=1/4.0
>>>num
0.25
>>>type(num)
<class 'float'>
>>> 1/3.0
0.3333333333333333
>>> import math
>>>[Link](2.3)
>>>[Link](2.6)
>>>[Link](2.69)
2
[Link]:
To perform a collection of characters and string operation will enter in to
the usage of string concept. Will determine the string in the single quotes(‘’) or
otherwise with in single double quotes(“”) or otherwise triple double
quotes(“”””””).
EXAMPLE
>>> s='welcome'
>>>s
'welcome'
>>> s="""welcome"""
>>>s
'welcome'
>>> s='hai "[Link]"'
>>>s
'hai "[Link]"'
>>> type(s)
<class 'str'>
>>> s="""hai "[Link]". don't you have pencil"""
>>>s
'hai "[Link]". don\'t you have pencil'
3. LISTS:
It is stored as an “ordered sequence of items, these items are MUTABLE”
(can modify, change, delete).
Items separated with commas are enclosed with square brackets or
list ([]).
EXAMPLE:
a=[5,10,15,20,25,30,35,40,45,50]
Print (“a[2]= “,a[2])
OUTPUT=>a[2]= 15
[Link]:
It is an ordered sequence of items same as list, but it is IMMUTABLE.
It is defined by parenthesis ()
EXAMPLE:
t= (5,’livewire’, 1+4j)
OUTPUT=> (5,’livewire’, (1+4j))
5. SET
It is an unordered collection of unique elements. And it IMMUTABLE. It
is defined by curly braces ({}).
EXAMPLE:
r= {10, 20, 30, 40, 50}
OUTPUT=> {40, 10, 50, 20, 30}
6. DICTIONARY
It is an unordered collection of Key-value pairs.
It is written with curly braces ({:}).
EXAMPLE:
d= {1:’robert’, 2:’surya’, 3:’kumar’}
d=enter
OUTPUT=> {1:’robert’, 2:’surya’, 3:’kumar’}
MAIN EXAMPLE:
>>l=[1,2,3,4,5]-----List
>>l
[1,2,3,4,5]
>>type(l)
<class ‘list’>
>>t=(1,2,3,4,5)--------Tuple
>>t
(1,2,3,4,5)
>>type(t)
<class ‘tuple’)
>>s={1,2,3,4,5}-----------Set
>>s
{1,2,3,4,5}
>>type(s)
<class ‘set’>
>>d={1:’surya’,2:’kumar’,3:’gopi’,4:’dhinakar’}------Dictionary
>>d
{1:’surya’ , 2:’kumar’ , 3:’gopi’ , 4:’dhinakar’}
>>type(d)
<class ‘dict’>
PYTHON INPUT AND OUTPUT STATEMENTS
Example 1: Python Output
In Python, we can simply use the print() function to print output.
print('Python is powerful')
# Output: Python is powerful
Example 2: Python print() with end Parameter
# print with end whitespace
print('Good Morning!', end= ' ')
print('It is rainy today')
Output
Good Morning! It is rainy today
Example 3: Python print() with sep parameter
print('New Year', 2023, 'See you soon!', sep= '. ')
Run Code
Output
New Year. 2023. See you soon!
Example 4: Print Python Variables and Literals
We can also use the print() function to print Python variables. For example,
number = -10.6
name = "Programiz"
# print literals
print(5)
# print variables
print(number)
print(name)
Run Code
Output
5
-10.6
Programiz
Example 5: Print Concatenated Strings
print('Programiz is ' + 'awesome.')
Output
Programiz is awesome.
Output formatting
x=5
y = 10
print('The value of x is {} and y is {}'.format(x,y))
Python Input
While programming, we might want to take the input from the user. In Python,
we can use the input() function.
Syntax of input()
input(prompt)
Here, prompt is the string we wish to display on the screen. It is optional.
Example: Python User Input
# using input() to take user input
num = input('Enter a number: ')
print('You Entered:', num)
print('Data type of num:', type(num))
Output
Enter a number: 10
You Entered: 10
Data type of num: <class 'str'>
num = int(input('Enter a number: '))
Here, the data type of the user input is converted from string to integer .