KEMBAR78
Basic of Python- Hands on Session | PPTX
Online Presentation on
Learn Python: Python for
beginners
Presented by
Prof. DharmeshTank
CE / IT Department
09-May-2020
Outline
 What and Why Python?
 Installation of Python
 Editors used for Python
 Variable declaration, Numbers & Data types
 Operators, String, List,Tuples, Dictionary
 Conditional Statements
 Looping Statements
 Application of Python language
 Conclusion
What is
Python?
Python is an interpreted, object-
oriented, high-level programming
language with dynamic semantics.
Source: https://www.python.org/
Why Python?
 It is portable, expandable, and embeddable.
 It can easily managing and organizing complex data.
 It’s syntax are clean.
 Python is the language of choice for the Machine Learning,
AI, Data Science, Raspberry Pi.
 Python offers tools that streamline the IoT development
process, such as webrepl.
 Since Python is an interpreted language, you can easily
test your solution without compiling the code or flashing
the device.
Features of
Python
Source: https://www.data-flair.training%2Fblogs%2Ffeatures-of-python%2F&psig=AOvVaw 2UNLNd8CUxNHuaHfuDj_-
s&ust=1589017513177810
Installation of
Python
Source: https://www.python.org/downloads/
EditorsUsed
for Python
 Python IDLE
 SublimeText
 Atom
 Jupiter
 PyDev
 Anaconda
 PyCharm
 Spyder
 Visual Studio IDE
 Vi /Vim (Used in Linux)
 Thonny (Used in Linux)
Source: www.datacamp.com%2Fcommunity%2Ftutorials%2Ftop-python-ides-for-2019&psig=AOvVaw0bp2ioDTCGM
Variable
declaration &
Data types
• What are the different data types in Python ?
In Python, data types are broadly classified into the
following:
1. Numbers
2. List
3.Tuple
4. Strings
5. Dictionary
• How to define a variable?
Syntax: VariableName = value
Example: phoneNo = 12345
Marks = 85.45
• How to comments?
Syntax: #variableName = value
Example: >>> # a=10
Operators
1. Assignment Operator (‘=‘)
2. Arithmetic Operators
 Multiplication (‘*’)
 Division (‘/‘)
 Addition (‘+’)
 Subtraction (‘-‘)
 Modulo (‘%’)
3. Relational or Comparison Operators
 Equal to (‘==‘) , Greater than (‘>’), Lesser than (‘<‘) ,
Greater than or equal to (‘>=’) , Lesser than or equal to
(‘<=‘), Not equal to (!=)
4. Logical Operators
 and -> Example: ((5 > 3) and (3 < 5)) True
 or -> Example: ((5 < 3) or (3 < 5)) True
 not -> Example: not (5<3) returnsTrue (reverse of
False).
Implementation
String
 How to define a string ?
Syntax :
stringName = “string”or stringName = ‘string’
Example:
programmingLanguage = “Python”
or
programmingLanguage = ‘Python’
 The starting index of any string is zero.
Implementation
ofString in
Python
String In-built
function
 upper() -
Syntax : stringName.upper()
 lower() -
Syntax : stringName.lower()
 replace() -
Syntax: stringName.replace(“Old Str”, “New Str”)
 length -
Syntax: len(stringName)
Implementation
ofString
Function in
Python
List
 A list is a container that holds many objects under a
single name.
Syntax : listName = [object1, object2, object3]
Example: fruit = [‘Apple', ‘Mango', ‘Orange’]
 It is same as array in C, C++ or JAVA.
 To access the list :
Example : fruit[0] = Apple, fruit[1] = Mango,
fruit[2] = Orange
ListOperations
 append() - To append any value in list
Syntax : list.append(element)
 insert() - To Insert at specific place in list
Syntax : list.insert(index, element)
 remove() - To remove the element from list
Syntax: list.remove(element)
 sort -To sort the list in ascending order
Syntax: list.sort()
 reverse -To reverse the list
Syntax: list.reverse()
 pop -To delete the specific index value
Syntax: list.pop(index)
Implementation
of List
Functions
Tuples
• A tuple is a container that holds many objects under a single
name.
• A tuple is immutable which means, a tuple once defined
cannot be modified.
Syntax : tupleName = (object1, object2, object3)
Example: ImpDate = (“11-09-1989”, “13-2-2020”)
• To access the values in a tuple
>>> ImpDate[1]
>>>13-2-2020
• To delete a tuple
Syntax: del(tupleName)
Example: del(ImpDate)
Dictionary
• A dictionary is a set of key-value pairs referenced by a
single name.
Syntax : dictionaryName = {“keyOne” : “valueOne”,
“keyTwo”: “valueTwo”}
Example:>>> colorOfFruits = {“apple”: “red”,
“mango”: “yellow”, “orange”: “orange”}
• To Retrieve the value of dictionary
Syntax: dictionaryName[“key”]
Example: >>>colorOfFruits[“mango”]
>>>yellow
Dictionary
inbuilt
Functions
 List all keys : keys() is used to list all the keys in a dictionary.
Syntax: dictionaryName.keys()
 List all values : values() is used to list all the values in a dictionary
Syntax: dictionaryName.values()
 Delete a key-value pair : del keyword is used to delete a key-
value pair from a dictionary
Syntax: del dictionaryName[“key”]
 Copy a dictionary into another : is used to copy the contents of
one dictionary to another
Syntax: dictionaryTwo = dictionaryOne.copy()
 Clear a dictionary: is used to clear the contents of a dictionary
and make it empty .
Implementation
of Dictionary &
It’s Functions
 Condition statements are a block of
statements whose execution depends on a
certain condition.
 Indentation play a very important role over
here.
 Different type of condition statements:
1. If statement
2. If-else statement
3. If-elif-else statement
4. Nested if
Control
Statement
(Condition)
Implementation
ofCondition
Statement
1. If statement
2. If-else statement
Indentation
Continue…. 4. Nested if statement
3. If-elif-else statement
 Loop statements : Looping is used to repeatedly
perform a block of statements over and over again.
 Different type of loop statements:
1. For loop
2. While loop
Control
Statement
(Loop)
1. For loop
statement
• The number of iterations to
be performed depends upon
the length of the list
• Syntax:
for count in list:
statement 1
statement 2…
statement n
• Here count is a iterative
variable who’s value start
from first value of the list .
• And, list is the array in
python.
• end = ‘ ’ is used to end the
print statement with a
white space instead of a
new line.
2.While loop
statement
• It repeatedly execute a
block of statements as long
as the condition mentioned
holds true.
Syntax:
while condition:
statement 1
statement 2…
statement n
• Here condition is used to
control the statement.
• while True: statement used
for infinite no of iteration.
Additional
Statement
 Break: A break
statement is used to
stop a loop from
further execution.
 Example:
>>>len=1
>>>while len>0:
if len == 3:
break
print(len)
len=len+1
 Else:The block of
statements in the else
block gets executed if
the break statement
in the looping
condition was
executed.
 Example:
>>> len=1
>>>while len<=3:
if len ==5:
break
print(len)
len=len+1
else:
print(“Break
statement was
executed”)
 Continue: Continue
statement is used to
skip a particular
iteration of the loop.
 Example:
>>> len = 1
>>>while len<=4:
if len ==2:
len=len+1
continue
print(len)
len=len+1
Application of
Python
Source: https://www.fiverr.com/
Real world
Application of
Python
 BitTorrent is made up in Python
 Web and Internet Development
 Scientific and Numeric: SciPy, Pandas, Ipython
 Business Applications : Odoo, Tryton
Source: topdevelopers.co%2Fblog%2F10-reasons-to-choose-python-web-development-project%2F&psig=AOvVaw
2drpI11_4MB70 UCf_c7W0S&ust=1589011542035214
Thank you
&
Suggestions or
Any Questions

Basic of Python- Hands on Session

  • 1.
    Online Presentation on LearnPython: Python for beginners Presented by Prof. DharmeshTank CE / IT Department 09-May-2020
  • 2.
    Outline  What andWhy Python?  Installation of Python  Editors used for Python  Variable declaration, Numbers & Data types  Operators, String, List,Tuples, Dictionary  Conditional Statements  Looping Statements  Application of Python language  Conclusion
  • 3.
    What is Python? Python isan interpreted, object- oriented, high-level programming language with dynamic semantics. Source: https://www.python.org/
  • 4.
    Why Python?  Itis portable, expandable, and embeddable.  It can easily managing and organizing complex data.  It’s syntax are clean.  Python is the language of choice for the Machine Learning, AI, Data Science, Raspberry Pi.  Python offers tools that streamline the IoT development process, such as webrepl.  Since Python is an interpreted language, you can easily test your solution without compiling the code or flashing the device.
  • 5.
  • 6.
  • 7.
    EditorsUsed for Python  PythonIDLE  SublimeText  Atom  Jupiter  PyDev  Anaconda  PyCharm  Spyder  Visual Studio IDE  Vi /Vim (Used in Linux)  Thonny (Used in Linux) Source: www.datacamp.com%2Fcommunity%2Ftutorials%2Ftop-python-ides-for-2019&psig=AOvVaw0bp2ioDTCGM
  • 8.
    Variable declaration & Data types •What are the different data types in Python ? In Python, data types are broadly classified into the following: 1. Numbers 2. List 3.Tuple 4. Strings 5. Dictionary • How to define a variable? Syntax: VariableName = value Example: phoneNo = 12345 Marks = 85.45 • How to comments? Syntax: #variableName = value Example: >>> # a=10
  • 9.
    Operators 1. Assignment Operator(‘=‘) 2. Arithmetic Operators  Multiplication (‘*’)  Division (‘/‘)  Addition (‘+’)  Subtraction (‘-‘)  Modulo (‘%’) 3. Relational or Comparison Operators  Equal to (‘==‘) , Greater than (‘>’), Lesser than (‘<‘) , Greater than or equal to (‘>=’) , Lesser than or equal to (‘<=‘), Not equal to (!=) 4. Logical Operators  and -> Example: ((5 > 3) and (3 < 5)) True  or -> Example: ((5 < 3) or (3 < 5)) True  not -> Example: not (5<3) returnsTrue (reverse of False).
  • 10.
  • 11.
    String  How todefine a string ? Syntax : stringName = “string”or stringName = ‘string’ Example: programmingLanguage = “Python” or programmingLanguage = ‘Python’  The starting index of any string is zero.
  • 12.
  • 13.
    String In-built function  upper()- Syntax : stringName.upper()  lower() - Syntax : stringName.lower()  replace() - Syntax: stringName.replace(“Old Str”, “New Str”)  length - Syntax: len(stringName)
  • 14.
  • 15.
    List  A listis a container that holds many objects under a single name. Syntax : listName = [object1, object2, object3] Example: fruit = [‘Apple', ‘Mango', ‘Orange’]  It is same as array in C, C++ or JAVA.  To access the list : Example : fruit[0] = Apple, fruit[1] = Mango, fruit[2] = Orange
  • 16.
    ListOperations  append() -To append any value in list Syntax : list.append(element)  insert() - To Insert at specific place in list Syntax : list.insert(index, element)  remove() - To remove the element from list Syntax: list.remove(element)  sort -To sort the list in ascending order Syntax: list.sort()  reverse -To reverse the list Syntax: list.reverse()  pop -To delete the specific index value Syntax: list.pop(index)
  • 17.
  • 18.
    Tuples • A tupleis a container that holds many objects under a single name. • A tuple is immutable which means, a tuple once defined cannot be modified. Syntax : tupleName = (object1, object2, object3) Example: ImpDate = (“11-09-1989”, “13-2-2020”) • To access the values in a tuple >>> ImpDate[1] >>>13-2-2020 • To delete a tuple Syntax: del(tupleName) Example: del(ImpDate)
  • 19.
    Dictionary • A dictionaryis a set of key-value pairs referenced by a single name. Syntax : dictionaryName = {“keyOne” : “valueOne”, “keyTwo”: “valueTwo”} Example:>>> colorOfFruits = {“apple”: “red”, “mango”: “yellow”, “orange”: “orange”} • To Retrieve the value of dictionary Syntax: dictionaryName[“key”] Example: >>>colorOfFruits[“mango”] >>>yellow
  • 20.
    Dictionary inbuilt Functions  List allkeys : keys() is used to list all the keys in a dictionary. Syntax: dictionaryName.keys()  List all values : values() is used to list all the values in a dictionary Syntax: dictionaryName.values()  Delete a key-value pair : del keyword is used to delete a key- value pair from a dictionary Syntax: del dictionaryName[“key”]  Copy a dictionary into another : is used to copy the contents of one dictionary to another Syntax: dictionaryTwo = dictionaryOne.copy()  Clear a dictionary: is used to clear the contents of a dictionary and make it empty .
  • 21.
  • 22.
     Condition statementsare a block of statements whose execution depends on a certain condition.  Indentation play a very important role over here.  Different type of condition statements: 1. If statement 2. If-else statement 3. If-elif-else statement 4. Nested if Control Statement (Condition)
  • 23.
  • 24.
    Continue…. 4. Nestedif statement 3. If-elif-else statement
  • 25.
     Loop statements: Looping is used to repeatedly perform a block of statements over and over again.  Different type of loop statements: 1. For loop 2. While loop Control Statement (Loop)
  • 26.
    1. For loop statement •The number of iterations to be performed depends upon the length of the list • Syntax: for count in list: statement 1 statement 2… statement n • Here count is a iterative variable who’s value start from first value of the list . • And, list is the array in python. • end = ‘ ’ is used to end the print statement with a white space instead of a new line.
  • 27.
    2.While loop statement • Itrepeatedly execute a block of statements as long as the condition mentioned holds true. Syntax: while condition: statement 1 statement 2… statement n • Here condition is used to control the statement. • while True: statement used for infinite no of iteration.
  • 28.
    Additional Statement  Break: Abreak statement is used to stop a loop from further execution.  Example: >>>len=1 >>>while len>0: if len == 3: break print(len) len=len+1  Else:The block of statements in the else block gets executed if the break statement in the looping condition was executed.  Example: >>> len=1 >>>while len<=3: if len ==5: break print(len) len=len+1 else: print(“Break statement was executed”)  Continue: Continue statement is used to skip a particular iteration of the loop.  Example: >>> len = 1 >>>while len<=4: if len ==2: len=len+1 continue print(len) len=len+1
  • 29.
  • 30.
    Real world Application of Python BitTorrent is made up in Python  Web and Internet Development  Scientific and Numeric: SciPy, Pandas, Ipython  Business Applications : Odoo, Tryton Source: topdevelopers.co%2Fblog%2F10-reasons-to-choose-python-web-development-project%2F&psig=AOvVaw 2drpI11_4MB70 UCf_c7W0S&ust=1589011542035214
  • 31.

Editor's Notes

  • #10 = operator -> Assigns the value at the right hand side to the variable at the left hand side.
  • #27 Also for is used within specific range >>> for i in range(1,6): print(i) 1 2 3 4 5 >>>
  • #29 While break statement stops the whole loop from execution, continue stops just an iteration of that loop.