SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Python Programming
By: Swati Choudhary
Programming : Python
‱ What is Python ?
A dynamic, open source programming language with a focus on
simplicity and productivity.
It has an elegant syntax that is natural to read and easy to write.
There are so many programming Languages.
Why Python ?
Why Python?
 Python is Simple & Beautiful
 Python is Object-Oriented
‱ Structure supports concepts as Polymorphism, Operation overloading & Multiple Inheritance
 Python is Free (Open Source Language )
‱ Downloading & Installing Python is Free & Easy
‱ Source Code is easily Accessible
 Python is Portable & Powerful
‱ Runs virtually on every major Platforms used today
‱ Dynamic Typing, Built-in types & tools, Library Utilities, Automatic Memory Management
Why Python?
Python Versions
Python 2.x is legacy; Python 3.x is the present and future of the language.
The most visible difference is probably the way the “print” statement works.
In python2 it’s a statement
print “Hello World!”
In Python3 it’s a function
print(“Hello World!”)
Python Strings:
Strings in Python are identified as a contiguous set of characters in between
quotation marks.
str = 'Hello World!'
Print(str) # Prints complete string
print(str[0]) # Prints first character of the string
Print(str[2:5]) # Prints characters starting from 3rd to 6th
print(str[2:]) # Prints string starting from 3rd character
print(str * 2) # Prints string two times
print(str + "TEST“) # Prints concatenated string
Python Lists:
Lists are the most versatile of Python's compound data types. A list
contains items separated by commas and enclosed within square
brackets ([]).
list1 = [ ‘hello', 786 , 4.1, ‘Ram', 702 ]
list2 = [123, ‘Victor']
Nested List
my_list = ["mouse", [8, 4, 6], ['a']]
Python List Methods
Methods that are available with list object in Python programming are tabulated below.
They are accessed as list.method()
append() - Add an element to the end of the list
extend() - Add all elements of a list to another list
insert() - Insert an item at the defined index
remove() - Removes an item from the list
pop() - Removes and returns an element at the given index
clear() - Removes all items from the list
index() - Returns the index of the first matched item
count() - Returns the count of number of items passed as an argument
sort() - Sort items in a list in ascending order
reverse() - Reverse the order of items in the list
copy() - Returns a shallow copy of the list
Python Tuples:
A tuple is another sequence data type that is similar to the list. Unlike
lists, however, tuples are enclosed within parentheses.
tuple1 = ( ‘hello', 786 , 2.23, ‘victor', 70.2 )
tuple2 = (123, ‘jay')
print(tuple1) # Prints complete list
print(tuple1[0]) # Prints first element of the list
print(tuple1[1:3]) # Prints elements starting from 2nd to 4th
print(tuple1[2:]) # Prints elements starting from 3rd element
print(tuple2 * 2) # Prints list two times
print(tuple1 + tuple2) # Prints concatenated lists
Python Dictionary:
Python 's dictionaries consist of key-value pairs.
dict1 = {'name': 'john','code':6734, 'dept': 'sales'}
print(dict1['name’]) # Prints value for 'one' key
print(dict1['code’]) # Prints value for 2 key
print(dict1) # Prints complete dictionary
print(dict1.keys()) # Prints all the keys
Print(dict1.values()) # Prints all the values
Python Operators
‱ Arithmetic operators (+, _, *, /, %, //, **)
‱ Comparison operators (>, <, ==, !=, >=, <=)
‱ Logical operators (And, OR, NOT)
‱ Bitwise operators (|OR, ^ XOR, ~ COMP)
‱ Assignment operators (=, +=, -=, *=, /=, //=, %=)
‱ Special operators
‱ Identity operators (is, is not)
‱ Membership operators (in, not in)
If else structure[conditional statement]
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
For loop using Range
# Prints out the numbers 0,1,2,3,4
for x in range(5):
print(x)
# Prints out 3,4,5
for x in range(3, 6):
print(x)
# Prints out 3,5,7
for x in range(3, 8, 2):
print(x)
While loop
while expression:
statements(s)
"break" and "continue" statements
break is used to exit a for loop or a while loop, whereas continue is used to skip the current
block, and return to the "for" or "while" statement
Defining Functions
def calculate(a,b):
print("Sum is=",a+b)
print("Difference is=",a-b)
print("Product is=",a*b)
calculate(20,10)
Functions are nothing but the pieces of code which are define for it
re-usability any time we call it
IoT example
# Program to load data into cloud
import time # To use sleep function
import requests
import random
baseurl="https://api.thingspeak.com/update?api_key="
apikey=“XXXXXXXXXXXX" #WriteAPI key
while True:
temp=random.randrange(15,50)
hum=random.randrange(30,70)
x=requests.get(baseurl+apikey+"&field1=%d&field2=%d"%(temp,hum))
time.sleep(1)
print(x)

Weitere Àhnliche Inhalte

Ähnlich wie Python_IoT.pptx

Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 

Ähnlich wie Python_IoT.pptx (20)

Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.ppt
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security Professionals
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdf
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Python lists
Python listsPython lists
Python lists
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
Python for Beginners(v1)
Python for Beginners(v1)Python for Beginners(v1)
Python for Beginners(v1)
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptx
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
Python programming
Python programmingPython programming
Python programming
 

KĂŒrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

KĂŒrzlich hochgeladen (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Python_IoT.pptx

  • 2. Programming : Python ‱ What is Python ? A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
  • 3. There are so many programming Languages. Why Python ?
  • 4. Why Python?  Python is Simple & Beautiful  Python is Object-Oriented ‱ Structure supports concepts as Polymorphism, Operation overloading & Multiple Inheritance  Python is Free (Open Source Language ) ‱ Downloading & Installing Python is Free & Easy ‱ Source Code is easily Accessible  Python is Portable & Powerful ‱ Runs virtually on every major Platforms used today ‱ Dynamic Typing, Built-in types & tools, Library Utilities, Automatic Memory Management
  • 6. Python Versions Python 2.x is legacy; Python 3.x is the present and future of the language. The most visible difference is probably the way the “print” statement works. In python2 it’s a statement print “Hello World!” In Python3 it’s a function print(“Hello World!”)
  • 7. Python Strings: Strings in Python are identified as a contiguous set of characters in between quotation marks. str = 'Hello World!' Print(str) # Prints complete string print(str[0]) # Prints first character of the string Print(str[2:5]) # Prints characters starting from 3rd to 6th print(str[2:]) # Prints string starting from 3rd character print(str * 2) # Prints string two times print(str + "TEST“) # Prints concatenated string
  • 8. Python Lists: Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). list1 = [ ‘hello', 786 , 4.1, ‘Ram', 702 ] list2 = [123, ‘Victor'] Nested List my_list = ["mouse", [8, 4, 6], ['a']]
  • 9. Python List Methods Methods that are available with list object in Python programming are tabulated below. They are accessed as list.method() append() - Add an element to the end of the list extend() - Add all elements of a list to another list insert() - Insert an item at the defined index remove() - Removes an item from the list pop() - Removes and returns an element at the given index clear() - Removes all items from the list index() - Returns the index of the first matched item count() - Returns the count of number of items passed as an argument sort() - Sort items in a list in ascending order reverse() - Reverse the order of items in the list copy() - Returns a shallow copy of the list
  • 10. Python Tuples: A tuple is another sequence data type that is similar to the list. Unlike lists, however, tuples are enclosed within parentheses. tuple1 = ( ‘hello', 786 , 2.23, ‘victor', 70.2 ) tuple2 = (123, ‘jay') print(tuple1) # Prints complete list print(tuple1[0]) # Prints first element of the list print(tuple1[1:3]) # Prints elements starting from 2nd to 4th print(tuple1[2:]) # Prints elements starting from 3rd element print(tuple2 * 2) # Prints list two times print(tuple1 + tuple2) # Prints concatenated lists
  • 11. Python Dictionary: Python 's dictionaries consist of key-value pairs. dict1 = {'name': 'john','code':6734, 'dept': 'sales'} print(dict1['name’]) # Prints value for 'one' key print(dict1['code’]) # Prints value for 2 key print(dict1) # Prints complete dictionary print(dict1.keys()) # Prints all the keys Print(dict1.values()) # Prints all the values
  • 12. Python Operators ‱ Arithmetic operators (+, _, *, /, %, //, **) ‱ Comparison operators (>, <, ==, !=, >=, <=) ‱ Logical operators (And, OR, NOT) ‱ Bitwise operators (|OR, ^ XOR, ~ COMP) ‱ Assignment operators (=, +=, -=, *=, /=, //=, %=) ‱ Special operators ‱ Identity operators (is, is not) ‱ Membership operators (in, not in)
  • 13. If else structure[conditional statement] if expression1: statement(s) elif expression2: statement(s) elif expression3: statement(s) else: statement(s)
  • 14. For loop using Range # Prints out the numbers 0,1,2,3,4 for x in range(5): print(x) # Prints out 3,4,5 for x in range(3, 6): print(x) # Prints out 3,5,7 for x in range(3, 8, 2): print(x)
  • 15. While loop while expression: statements(s) "break" and "continue" statements break is used to exit a for loop or a while loop, whereas continue is used to skip the current block, and return to the "for" or "while" statement
  • 16. Defining Functions def calculate(a,b): print("Sum is=",a+b) print("Difference is=",a-b) print("Product is=",a*b) calculate(20,10) Functions are nothing but the pieces of code which are define for it re-usability any time we call it
  • 17. IoT example # Program to load data into cloud import time # To use sleep function import requests import random baseurl="https://api.thingspeak.com/update?api_key=" apikey=“XXXXXXXXXXXX" #WriteAPI key while True: temp=random.randrange(15,50) hum=random.randrange(30,70) x=requests.get(baseurl+apikey+"&field1=%d&field2=%d"%(temp,hum)) time.sleep(1) print(x)