SlideShare a Scribd company logo
Programming in Python
Vikram Neerugatti
content
• Introduction to python
• Installation of Python in windows
• Running Python
• Arithmetic operators
• Values and types
• Formal and Natural languages
Introduction to Python
• Dynamic interoperated language that allows both functional and object oriented programming languages
• Interpreter
• Python is a language
• Simple
• On all platforms
• Real programming language
• High level problems
• Can split into modules
• GUI can be done
• It is a interpreter language
• Very short compare with other languages
• Indents will be used instead of brackets
• After the bbc shows monty python cant do anything on reptiles
Installation of Python in windows
Installation of Python in windows
Installation of Python in windows
Running a python
• Start
• Select python
• In the prompt type the statement
Print (“hello world”)
Arithmetic operations
• In the prompt of the python type
• 3+4
• 3-4
• ¾
• 3%4
• 3*4
• Type with variables also
• A=3
• B=5, etc.
Values and types
• Python numbers
• Integer
• 2,4,5
• Float
• 2.3,4.5,7.8
• Complex
• 3+5J
• Python lists
• can be any
• [3, 4, 5, 6, 7, 9]
• ['m', 4, 4, 'nani']
• Slicing operator, list index starts from zero
• A[4],a[:2],a[1:2]
• mutable
• Python tuples ()
• Cannot change, slicing can be done a[4].
• immutable
Values and types
• Python Strings
• Sequence of Characters
• Single line
• Ex. s='zaaaa nani'
• Multi line
• Ex. s='''zaaaa nani
• print(s)
• nani'''
• print (s)
• Sliicing can be done
• Ex. S[5]
Values and types
• Python sets
• Collection of unordered elements, elements will not be in order
• S={3,4,5.6,’g’,8}
• Can do intersection (&), union(|), difference (-), ^ etc.
• Ex. A&b, a|b, a-b, a^b’
• Remove duplicates
• {5,5,5,7,88,8,88}
• No slicing can be done, because elements are not in order.
• Python dictionaries
Python dictionaries
• Python dictionary is an unordered collection of items.
• While other compound data types have only value as an element, a
dictionary has a key: value pair.
• Dictionaries are optimized to retrieve values when the key is known.
• Creating a dictionary is as simple as placing items inside curly braces {}
separated by comma.
• An item has a key and the corresponding value expressed as a pair, key:
value.
• While values can be of any data type and can repeat, keys must be of
immutable type (string, number or tuple with immutable elements) and
must be unique.
Python dictionaries (creating)
1.# empty dictionary
2.my_dict = {}
4.# dictionary with integer keys
5.my_dict = {1: 'apple', 2: 'ball'}
7.# dictionary with mixed keys
8.my_dict = {'name': 'John', 1: [2, 4, 3]}
10.# using dict()
11.my_dict = dict({1:'apple', 2:'ball'})
13.# from sequence having each item as a pair
14.my_dict = dict([(1,'apple'), (2,'ball')])
Python dictionaries (accesing)
• my_dict = {'name':'Jack', 'age': 26}
• # Output: Jack
• print(my_dict['name’])
• # Output: 26
• print(my_dict.get('age’))
• # Trying to access keys which doesn't exist throws error#
my_dict.get('address’)
• # my_dict['address’]
• Key in square brackets/get(), if you use get(), instead of error , none will be
displayed.
Change/ add elements in a dictionaries
• my_dict = {'name':'Jack', 'age': 26}
• # update value
• my_dict['age'] = 27
• #Output: {'age': 27, 'name': 'Jack’}
• print(my_dict)
• # add item
• my_dict['address'] = 'Downtown’
• # Output: {'address': 'Downtown', 'age': 27, 'name': 'Jack'}print(my_dict)
• Mutable, if key is there: value will be updated, if not created new one.
How to remove or delete the item in
dictionaries
• We can remove a particular item in a dictionary by using the method
pop(). This method removes as item with the provided key and
returns the value.
• The method, popitem() can be used to remove and return an
arbitrary item (key, value) form the dictionary. All the items can be
removed at once using the clear() method.
• We can also use the del keyword to remove individual items or the
entire dictionary itself.
How to remove or delete the item in
dictionaries
• # create a dictionary squares = {1:1, 2:4, 3:9, 4:16, 5:25}
• # remove a particular item # Output: 16
• print(squares.pop(4)) # Output: {1: 1, 2: 4, 3: 9, 5: 25}print(squares)
• # remove an arbitrary item
• # Output: (1, 1) print(squares.popitem()) # Output: {2: 4, 3: 9, 5: 25} print(squares)
• # delete a particular item
• del squares[5] # Output: {2: 4, 3: 9}print(squares)
• # remove all items
• squares.clear()
• # Output: {}
• print(squares)
• # delete the dictionary itself
• del squares
• # Throws Error# print(squares)
Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1
Nested Dictionary
• In Python, a nested dictionary is a dictionary inside a dictionary.
• It's a collection of dictionaries into one single dictionary.
Example:
nested_dict = { 'dictA': {'key_1': 'value_1’},
'dictB': {'key_2': 'value_2'}}
• Here, the nested_dict is a nested dictionary with the dictionary dictA
and dictB.
• They are two dictionary each having own key and value.
Nested dictionaries
Example:
>>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
2: {'name': 'Marie', 'age': '22', 'sex': 'Female’}}
>>print(people)
#Accessing elements
>>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
2: {'name': 'Marie', 'age': '22', 'sex': 'Female’}}
>>print(people[1]['name’])
>>print(people[1]['age’])
>>print(people[1]['sex'])
Add or updated the nested dictionaries
>>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
2: {'name': 'Marie', 'age': '22', 'sex': 'Female’}}
>>people[3] = {}
>>people[3]['name'] = 'Luna’
>>people[3]['age'] = '24’
>>people[3]['sex'] = 'Female’
>>people[3]['married'] = 'No’
>>print(people[3])
Add another dictionary
>>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
2: {'name': 'Marie', 'age': '22', 'sex': 'Female'},
3: {'name': 'Luna', 'age': '24', 'sex': 'Female', 'married': 'No’}}
>>people[4] = {'name': 'Peter', 'age': '29', 'sex': 'Male', 'married’:
'Yes’}
>>print(people[4]);
Delete elements from the dictionaries
>>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
2: {'name': 'Marie', 'age': '22', 'sex': 'Female'},
3: {'name': 'Luna', 'age': '24', 'sex': 'Female', 'married': 'No'},
4: {'name': 'Peter', 'age': '29', 'sex': 'Male', 'married': 'Yes’}}
>>del people[3]['married’]
>>del people[4]['married’]
>>print(people[3])
>>print(people[4])
How to delete the dictionary
>>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
2: {'name': 'Marie', 'age': '22', 'sex': 'Female'},
3: {'name': 'Luna', 'age': '24', 'sex': 'Female'},
4: {'name': 'Peter', 'age': '29', 'sex': 'Male’}}
>>del people[3], people[4]
>>print(people)
Natural Language and Formal Language
• The languages used by the humans called as a natural languages
• Examples: English, French, Telugu,etc.
• The languages designed and developed by the humans to
communicate with the machines is called as the formal languages.
• Example: C, C++, Java, Python, etc.
Summary
• Introduction to python
• Installation of Python in windows
• Running Python
• Arithmetic operators
• Values and types
• Formal and Natural languages
Any questions
• vikramneerugatti@gmail.com
• www.vikramneerugatti.com

More Related Content

PPTX
Dictionary in python
PPT
Building Single-Page Web Appplications in dart - Devoxx France 2013
PDF
Python Dictionary
PDF
Dynamic languages, for software craftmanship group
PPTX
Python dictionary
PPTX
Basics of Python programming (part 2)
PPT
Python tutorial
Dictionary in python
Building Single-Page Web Appplications in dart - Devoxx France 2013
Python Dictionary
Dynamic languages, for software craftmanship group
Python dictionary
Basics of Python programming (part 2)
Python tutorial

What's hot (19)

PPT
Python tutorialfeb152012
PDF
1. python
PDF
Datatypes in python
PDF
Truth, deduction, computation; lecture 2
PDF
Greach 2015 AST – Groovy Transformers: More than meets the eye!
PDF
G3 Summit 2016 - Taking Advantage of Groovy Annotations
PPTX
Python Training
PPTX
Python dictionary
PPTX
Datastructures in python
PDF
The Ring programming language version 1.10 book - Part 7 of 212
PDF
Python in 90 minutes
PPTX
Python Datatypes by SujithKumar
PPTX
.net F# mutable dictionay
PDF
Madrid gug - sacando partido a las transformaciones ast de groovy
PDF
The Ring programming language version 1.5.3 book - Part 6 of 184
PPTX
Coding in Kotlin with Arrow NIDC 2018
PDF
First few months with Kotlin - Introduction through android examples
PDF
DevNation'15 - Using Lambda Expressions to Query a Datastore
PDF
The Ring programming language version 1.5.4 book - Part 6 of 185
Python tutorialfeb152012
1. python
Datatypes in python
Truth, deduction, computation; lecture 2
Greach 2015 AST – Groovy Transformers: More than meets the eye!
G3 Summit 2016 - Taking Advantage of Groovy Annotations
Python Training
Python dictionary
Datastructures in python
The Ring programming language version 1.10 book - Part 7 of 212
Python in 90 minutes
Python Datatypes by SujithKumar
.net F# mutable dictionay
Madrid gug - sacando partido a las transformaciones ast de groovy
The Ring programming language version 1.5.3 book - Part 6 of 184
Coding in Kotlin with Arrow NIDC 2018
First few months with Kotlin - Introduction through android examples
DevNation'15 - Using Lambda Expressions to Query a Datastore
The Ring programming language version 1.5.4 book - Part 6 of 185
Ad

Similar to Programming in python Unit-1 Part-1 (20)

PPTX
Chapter 3-Data structure in python programming.pptx
PPTX
Dictionary in python Dictionary in python Dictionary in pDictionary in python...
PPT
ComandosDePython_ComponentesBasicosImpl.ppt
PDF
Python dictionaries
PPTX
Session10_Dictionaries.ppggyyyyyyyyyggggggggtx
PPTX
Dictionary.pptx
PPTX
Seventh session
PPTX
Data Type In Python.pptx
PPTX
Week 10.pptx
PDF
Dictionaries in Python programming for btech students
PDF
Python Variable Types, List, Tuple, Dictionary
PPTX
cover every basics of python with this..
PPT
Tuples, sets and dictionaries-Programming in Python
PPTX
Dictionaries.pptx
PPTX
Python data structures
PPTX
Dictionariesasdfghjsdfghjklsdfghjkl.pptx
PPTX
fundamental of python --- vivek singh shekawat
DOC
Revision Tour 1 and 2 complete.doc
PPTX
Python introduction data structures lists etc
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
Chapter 3-Data structure in python programming.pptx
Dictionary in python Dictionary in python Dictionary in pDictionary in python...
ComandosDePython_ComponentesBasicosImpl.ppt
Python dictionaries
Session10_Dictionaries.ppggyyyyyyyyyggggggggtx
Dictionary.pptx
Seventh session
Data Type In Python.pptx
Week 10.pptx
Dictionaries in Python programming for btech students
Python Variable Types, List, Tuple, Dictionary
cover every basics of python with this..
Tuples, sets and dictionaries-Programming in Python
Dictionaries.pptx
Python data structures
Dictionariesasdfghjsdfghjklsdfghjkl.pptx
fundamental of python --- vivek singh shekawat
Revision Tour 1 and 2 complete.doc
Python introduction data structures lists etc
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
Ad

More from Vikram Nandini (20)

PDF
IoT: From Copper strip to Gold Bar
PDF
Design Patterns
PDF
Linux File Trees and Commands
PDF
Introduction to Linux & Basic Commands
PDF
INTRODUCTION to OOAD
PDF
PDF
Manufacturing - II Part
PDF
Manufacturing
PDF
Business Models
PDF
Prototyping Online Components
PDF
Artificial Neural Networks
PDF
IoT-Prototyping
PDF
Design Principles for Connected Devices
PDF
Introduction to IoT
PDF
Embedded decices
PDF
Communication in the IoT
PDF
Introduction to Cyber Security
PDF
cloud computing UNIT-2.pdf
PDF
Introduction to Web Technologies
PDF
Cascading Style Sheets
IoT: From Copper strip to Gold Bar
Design Patterns
Linux File Trees and Commands
Introduction to Linux & Basic Commands
INTRODUCTION to OOAD
Manufacturing - II Part
Manufacturing
Business Models
Prototyping Online Components
Artificial Neural Networks
IoT-Prototyping
Design Principles for Connected Devices
Introduction to IoT
Embedded decices
Communication in the IoT
Introduction to Cyber Security
cloud computing UNIT-2.pdf
Introduction to Web Technologies
Cascading Style Sheets

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
master seminar digital applications in india
PPTX
Cell Structure & Organelles in detailed.
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Institutional Correction lecture only . . .
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PDF
Pre independence Education in Inndia.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Insiders guide to clinical Medicine.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Pharmacology of Heart Failure /Pharmacotherapy of CHF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
master seminar digital applications in india
Cell Structure & Organelles in detailed.
Microbial diseases, their pathogenesis and prophylaxis
Institutional Correction lecture only . . .
O7-L3 Supply Chain Operations - ICLT Program
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
Pre independence Education in Inndia.pdf
Renaissance Architecture: A Journey from Faith to Humanism

Programming in python Unit-1 Part-1

  • 2. content • Introduction to python • Installation of Python in windows • Running Python • Arithmetic operators • Values and types • Formal and Natural languages
  • 3. Introduction to Python • Dynamic interoperated language that allows both functional and object oriented programming languages • Interpreter • Python is a language • Simple • On all platforms • Real programming language • High level problems • Can split into modules • GUI can be done • It is a interpreter language • Very short compare with other languages • Indents will be used instead of brackets • After the bbc shows monty python cant do anything on reptiles
  • 7. Running a python • Start • Select python • In the prompt type the statement Print (“hello world”)
  • 8. Arithmetic operations • In the prompt of the python type • 3+4 • 3-4 • ¾ • 3%4 • 3*4 • Type with variables also • A=3 • B=5, etc.
  • 9. Values and types • Python numbers • Integer • 2,4,5 • Float • 2.3,4.5,7.8 • Complex • 3+5J • Python lists • can be any • [3, 4, 5, 6, 7, 9] • ['m', 4, 4, 'nani'] • Slicing operator, list index starts from zero • A[4],a[:2],a[1:2] • mutable • Python tuples () • Cannot change, slicing can be done a[4]. • immutable
  • 10. Values and types • Python Strings • Sequence of Characters • Single line • Ex. s='zaaaa nani' • Multi line • Ex. s='''zaaaa nani • print(s) • nani''' • print (s) • Sliicing can be done • Ex. S[5]
  • 11. Values and types • Python sets • Collection of unordered elements, elements will not be in order • S={3,4,5.6,’g’,8} • Can do intersection (&), union(|), difference (-), ^ etc. • Ex. A&b, a|b, a-b, a^b’ • Remove duplicates • {5,5,5,7,88,8,88} • No slicing can be done, because elements are not in order. • Python dictionaries
  • 12. Python dictionaries • Python dictionary is an unordered collection of items. • While other compound data types have only value as an element, a dictionary has a key: value pair. • Dictionaries are optimized to retrieve values when the key is known. • Creating a dictionary is as simple as placing items inside curly braces {} separated by comma. • An item has a key and the corresponding value expressed as a pair, key: value. • While values can be of any data type and can repeat, keys must be of immutable type (string, number or tuple with immutable elements) and must be unique.
  • 13. Python dictionaries (creating) 1.# empty dictionary 2.my_dict = {} 4.# dictionary with integer keys 5.my_dict = {1: 'apple', 2: 'ball'} 7.# dictionary with mixed keys 8.my_dict = {'name': 'John', 1: [2, 4, 3]} 10.# using dict() 11.my_dict = dict({1:'apple', 2:'ball'}) 13.# from sequence having each item as a pair 14.my_dict = dict([(1,'apple'), (2,'ball')])
  • 14. Python dictionaries (accesing) • my_dict = {'name':'Jack', 'age': 26} • # Output: Jack • print(my_dict['name’]) • # Output: 26 • print(my_dict.get('age’)) • # Trying to access keys which doesn't exist throws error# my_dict.get('address’) • # my_dict['address’] • Key in square brackets/get(), if you use get(), instead of error , none will be displayed.
  • 15. Change/ add elements in a dictionaries • my_dict = {'name':'Jack', 'age': 26} • # update value • my_dict['age'] = 27 • #Output: {'age': 27, 'name': 'Jack’} • print(my_dict) • # add item • my_dict['address'] = 'Downtown’ • # Output: {'address': 'Downtown', 'age': 27, 'name': 'Jack'}print(my_dict) • Mutable, if key is there: value will be updated, if not created new one.
  • 16. How to remove or delete the item in dictionaries • We can remove a particular item in a dictionary by using the method pop(). This method removes as item with the provided key and returns the value. • The method, popitem() can be used to remove and return an arbitrary item (key, value) form the dictionary. All the items can be removed at once using the clear() method. • We can also use the del keyword to remove individual items or the entire dictionary itself.
  • 17. How to remove or delete the item in dictionaries • # create a dictionary squares = {1:1, 2:4, 3:9, 4:16, 5:25} • # remove a particular item # Output: 16 • print(squares.pop(4)) # Output: {1: 1, 2: 4, 3: 9, 5: 25}print(squares) • # remove an arbitrary item • # Output: (1, 1) print(squares.popitem()) # Output: {2: 4, 3: 9, 5: 25} print(squares) • # delete a particular item • del squares[5] # Output: {2: 4, 3: 9}print(squares) • # remove all items • squares.clear() • # Output: {} • print(squares) • # delete the dictionary itself • del squares • # Throws Error# print(squares)
  • 20. Nested Dictionary • In Python, a nested dictionary is a dictionary inside a dictionary. • It's a collection of dictionaries into one single dictionary. Example: nested_dict = { 'dictA': {'key_1': 'value_1’}, 'dictB': {'key_2': 'value_2'}} • Here, the nested_dict is a nested dictionary with the dictionary dictA and dictB. • They are two dictionary each having own key and value.
  • 21. Nested dictionaries Example: >>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'}, 2: {'name': 'Marie', 'age': '22', 'sex': 'Female’}} >>print(people) #Accessing elements >>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'}, 2: {'name': 'Marie', 'age': '22', 'sex': 'Female’}} >>print(people[1]['name’]) >>print(people[1]['age’]) >>print(people[1]['sex'])
  • 22. Add or updated the nested dictionaries >>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'}, 2: {'name': 'Marie', 'age': '22', 'sex': 'Female’}} >>people[3] = {} >>people[3]['name'] = 'Luna’ >>people[3]['age'] = '24’ >>people[3]['sex'] = 'Female’ >>people[3]['married'] = 'No’ >>print(people[3])
  • 23. Add another dictionary >>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'}, 2: {'name': 'Marie', 'age': '22', 'sex': 'Female'}, 3: {'name': 'Luna', 'age': '24', 'sex': 'Female', 'married': 'No’}} >>people[4] = {'name': 'Peter', 'age': '29', 'sex': 'Male', 'married’: 'Yes’} >>print(people[4]);
  • 24. Delete elements from the dictionaries >>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'}, 2: {'name': 'Marie', 'age': '22', 'sex': 'Female'}, 3: {'name': 'Luna', 'age': '24', 'sex': 'Female', 'married': 'No'}, 4: {'name': 'Peter', 'age': '29', 'sex': 'Male', 'married': 'Yes’}} >>del people[3]['married’] >>del people[4]['married’] >>print(people[3]) >>print(people[4])
  • 25. How to delete the dictionary >>people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'}, 2: {'name': 'Marie', 'age': '22', 'sex': 'Female'}, 3: {'name': 'Luna', 'age': '24', 'sex': 'Female'}, 4: {'name': 'Peter', 'age': '29', 'sex': 'Male’}} >>del people[3], people[4] >>print(people)
  • 26. Natural Language and Formal Language • The languages used by the humans called as a natural languages • Examples: English, French, Telugu,etc. • The languages designed and developed by the humans to communicate with the machines is called as the formal languages. • Example: C, C++, Java, Python, etc.
  • 27. Summary • Introduction to python • Installation of Python in windows • Running Python • Arithmetic operators • Values and types • Formal and Natural languages