This presentation includes basics of python language.How to run basic programs of python? The one who is new to this language can easily understand this language after watching this presentation.
2. Introduction
Python is a general purpose, high level programming
language that is often applied in scripting roles.
so, python is programming language as well as
scripting language.
Python is also called interpreted language.
9 March 2019Python
3. History
Invented in Netherlands, early 90s by Guido van
Rossum
Python was conceived in the late 1980s and its
implementation was started in December 1989
Guido van Rossum is fan of ‘Monty Python’s Flying
Circus’, this is a famous TV show in Netherlands
Named after Monty Python
Open sourced from beginning
9 March 2019Python
4. Scope of Python
Desktop application
Web application
Games
Scientific application
Artificial Intelligence (A.I.)
Machine Learning (M.L)
Data Science
IoT (Internet of Things)
9 March 2019Python
5. What can I do with Python?
• System programming
• Graphical User Interface Programming
• Internet Scripting
• Component integration
• Database Programming
• Gaming, Images, XML, Robot and more
9 March 2019Python
6. Who uses Python TODAY…
• Python is being applied in real revenue-generating
products by real companies. For instance:
• Google is one of the Python users that included this
language in its web search system and employed Python’s
creator, too.
• YouTube video sharing service makes extensive use of
Python.
• ESRI uses Python as an end-user customization tool for its
popular GIS mapping products.
• iRobot uses Python to develop commercial robotic vacuum
cleaners.
• Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and
IBM use Python for hardware testing.
9 March 2019Python
7. Features of Python
Interpreted
You run the program straight from the source code.
Python program Bytecode a platforms native language
You can just copy over your code to another system and it will
auto-magically work! *with python platform
Object-Oriented
Simple and additionally supports procedural programming
Extensible – easily import other code
Easy to read- Code is more clearly defined.
Extensive libraries
(i.e. reg. expressions, doc generation, CGI, ftp, web browsers,
ZIP, WAV, cryptography, etc...) (wxPython, Twisted, Python
Imaging library)
9 March 2019Python
8. Why do people use Python…?
The following primary factors cited by Python
users seem to be these:
Python is object-oriented
Structure supports such concepts as
polymorphism,operation overloading, and multiple
inheritance.
It's free (open source)
Downloading and installing Python is free and
easy
Source code is easily accessible.
9 March 2019Python
9. Python on your systems
Its easy! Go to http://www.python.org/download/
Download your architecture binary, or source
Install, make, build whatever you need to do…
plenty of info on installation in readmes
Make your first program! (a simple on like the hello
world one will do just fine)
Two ways of running python code. Either in an
interpreter or in a file ran as an executable
Python
10. Starting IDLE on Windows
Start IDLE
Go to File menu and click on New Window
Type your program in
Go to File menu and click on Save. Type
in filename.py This will save it as a plain text
file, which can be opened in in any editor
you choose (like Notepad).
To run your program go to Run and
click Run Module.
9 March 2019Python
19. Python Code Execution
Source code you type is translated to byte code:
Python Virtual Machine. Your code is automatically
compiled, but then it is interpreted.
Source code extension is .py
Byte code extension is .pyc (compiled python code)
9 March 2019Python
20. Basic Syntax of Python
A Python identifier is a name used to identify a variable, function,
class, module or other object. An identifier starts with a letter A to Z
or a to z or an underscore (_) followed by zero or more letters,
underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $, and
% within identifiers. Python is a case sensitive programming
language.
Python provides no braces to indicate blocks of code for class and
function definitions or flow control. Blocks of code are denoted by
line indentation, which is rigidly enforced.
9 March 2019Python
21. Continued…
Python accepts single ('), double (") and triple (''' or """) quotes to
denote string literals, as long as the same type of quote starts and
ends the string.
A hash sign (#) that is not inside a string literal begins a comment.
9 March 2019Python
22. Standard Data types
String – ‘MyString’, and “MyString”
List – [ 69, 6.9, ‘mystring’, True]
Tuple – (69, 6.9, ‘mystring’, True) immutable
Set/frozenset – set([69, 6.9, ‘str’, True])
frozenset- ([69, 6.9, ‘str’, True]) –no duplicates &
unordered
Dictionary or hash – {‘key 1’: 6.9, ‘key2’: False} -
group of key and value pairs
9 March 2019Python
23. Strings
Strings in Python are identified as a contiguous set of
characters represented in the quotation marks.
Python allows for either pairs of single or double
quotes. Subsets of strings can be taken using the
slice operator ([ ] and [:] ) with indexes starting at 0 in
the beginning of the string and working their way from
-1 at the end.
The plus (+) sign is the string concatenation operator
and the asterisk (*) is the repetition operator.
9 March 2019Python
25. Lists
lists are the most versatile of Python's compound data
types. A list contains items separated by commas and
enclosed within square brackets ([ ]). To some extent, lists
are similar to arrays in C. One difference between them is
that all the items belonging to a list can be of different data
type.
The values stored in a list can be accessed using the slice
operator ([ ] and [:]) with indexes starting at 0 in the
beginning of the list and working their way to end -1. The
plus (+) sign is the list concatenation operator, and the
asterisk (*) is the repetition operator.
9 March 2019Python
29. CONDITIONAL STATEMENT
9 March 2019
Sr.No. Statement & Description
1. if statements An if statement consists of a boolean
expression followed by one or more statements.
2. if...else statements An if statement can be followed by an
optional else statement, which executes when the boolean
expression is FALSE.
3. nested if statements You can use one if or else if statement
inside another if or else if statement(s).
31. Loops
A loop statement allows us to
execute a statement or group of
statements multiple times.
Types of Loops:-
• While loop
• Do-while loop
• For loop
9 March 2019Python
33. Functions
A function is a block of organized, reusable
code that is used to perform a single, related
action. Functions provide better modularity
for your application and a high degree of
code reusing.
As you already know, Python gives you
many built-in functions like print(), etc. but
you can also create your own functions.
These functions are called user-defined
functions.
9 March 2019Python
34. Defining a function
You can define functions to provide the required
functionality. Here are simple rules to define a function in
Python.
Function blocks begin with the keyword def followed by the
function name and parentheses ( ( ) ).
Any input parameters or arguments should be placed within
these parentheses. You can also define parameters inside
these parentheses.
The code block within every function starts with a colon (:)
and is indented.
The statement return [expression] exits a function,
optionally passing back an expression to the caller. A return
statement with no arguments is the same as return None.
9 March 2019Python
36. Function with Description
1. cmp(list1, list2) Compares elements of both
lists.
2. len(list) Gives the total length of the list.
3. max(list) Returns item from the list with max
value.
4. min(list) Returns item from the list with min
value.
5. list(seq) Converts a tuple into list.
9 March 2019Python
37. Modules
Modules refer to a file containing Python statements and
definitions.
A file containing Python code, for e.g.: example.py is a module
and its module name would be example.
We use modules to break down large programs into small
manageable and organized files. Furthermore, modules provide
reusability of code.
We can define our most used functions in a module and import it,
instead of copying their definitions into different programs.
Let us create a module. Type the following and save it as
example.py
9 March 2019Python
38. Import Statement
The properties of one module we can use into another
module by using 'import ' statement.
Python support two type of import statement
1. Normal import
2. From import
Normal import
In normal import entire python file or module object is
imported.
Whenever we import a module by using normal import we
can access the properties of that module by using that
module.
9 March 2019
40. Continued...
From import
By using from import we can import the required
properties of module
Module search path
• Cwd
• Environment variables
• Installation dependent directories
if module is not found then we will get error
9 March 2019Python