SlideShare a Scribd company logo
1 of 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)

More Related Content

Similar to Python_IoT.pptx

Python. libraries. modules. and. all.pdf
Python. libraries. modules. and. all.pdfPython. libraries. modules. and. all.pdf
Python. libraries. modules. and. all.pdfprasenjitghosh1998
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.pptVicVic56
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security ProfessionalsAditya Shankar
 
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.pptxsangeeta borde
 
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.pdfExaminationSectionMR
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experiencedzynofustechnology
 
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)Pedro Rodrigues
 
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
 
Python interview questions
Python interview questionsPython interview questions
Python interview questionsPragati Singh
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxNimrahafzal1
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming LanguageTahani Al-Manie
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptxNawalKishore38
 
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.supriyasarkar38
 

Similar to Python_IoT.pptx (20)

Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python. libraries. modules. and. all.pdf
Python. libraries. modules. and. all.pdfPython. libraries. modules. and. all.pdf
Python. libraries. modules. and. all.pdf
 
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.
 

Recently uploaded

Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Paige Cruz
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)Wonjun Hwang
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 

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)