Embed presentation
Downloaded 237 times















![Data Structure: List A list is a data structure that holds an ordered collection of items fruits = [’apple’,’banana’,’orange’] marks = [12,15,17] avgs = [1.5, 4.5,7.8] avgm = [1.5, 4.5,7.8,avgs] lists are mutable elemnts can be accessed by index numbers either positive index or negative index can be used to access elements Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-16-2048.jpg&f=jpg&w=240)
![Data Structure: List elemnts can be accessed by index numbers fruits[0] elements can be accessed with positive or negative index avgs[-1] new elements can be appended to a list fruits.append(’cherry’) list can be sorted or reversed fruits.sort() fruits.reverse() length of a list can be identified by the ’len’ function len(fruits) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-17-2048.jpg&f=jpg&w=240)
![Data Structure: List elements can be deleted del fruits[0] list can be sliced new list = fruits[1:3] lists can be extended flowers = [’rose’,’lilly’,’tulip’] fruits.extend(flowers) the index method can be used to find index of an item in a list fruits.index(’apple’) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-18-2048.jpg&f=jpg&w=240)
![Data Structure: List The pop method removes an element from a list fruits.pop() The remove method is used to remove the first occurrence of a value: flowers = [’rose’,’lilly’,’tulip’,’rose’] flowers.remove(’rose’) The reverse method reverses the elements in the list. flowers.reverse() The sort method is used to sort lists in place flowers.sort() Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-19-2048.jpg&f=jpg&w=240)
![Data Structure: List >>> numbers = [5, 2, 9, 7] >>> numbers.sort(cmp) >>> numbers [2, 5, 7, 9] >>> x = [’aardvark’, ’abalone’, ’acme’, ’add’, ’aerate’] >>> x.sort(key=len) >>> x [’add’, ’acme’, ’aerate’, ’abalone’, ’aardvark’] >>> x = [4, 6, 2, 1, 7, 9] >>> x.sort(reverse=True) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-20-2048.jpg&f=jpg&w=240)


![Data Structure: Dictionary Another useful data type built into Python is the dictionary Dictionaries are sometimes found in other languages as associative memories or associative arrays. Dictionaries consist of pairs (called items) of keys and their corresponding values phonebook = {’Alice’: ’2341’, ’Beth’: ’9102’, ’Cecil’: ’3258’} phonebook[’Alice’] #’2341’ Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-23-2048.jpg&f=jpg&w=240)
![Basic Dictionary Operations len(d) returns the number of items (key-value pairs) in d d = {’Alice’: ’2341’, ’Beth’: ’9102’, ’Cecil’: ’325 len(d) 3 d[’Alice’] returns the value associated with the key k ie ”2341” d[’Alice’] = ’456’ associates the value ’456’ with the key ’Alice’ del d[’Alice’] deletes the item with key ’Alice’ ’Alice’ in d checks whether there is an item in d that has the key ’Alice’ Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-24-2048.jpg&f=jpg&w=240)
![Data Structure: Dictionary Key types: Dictionary keys dont have to be integers (though they may be). They may be any immutable type, such as floating-point (real) numbers, strings, or tuples. Automatic addition: You can assign a value to a key, even if that key isnt in the dictionary to begin with; in that case, a new item will be created. You cannot assign a value to an index outside the lists range (without using append or something like that). phonebook[’Ravi’] = ’567’ Membership: The expression k in d (where d is a dictionary) looks for a key, not a value. ’Alice’ in phonebook Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-25-2048.jpg&f=jpg&w=240)
![Data Structure: Dictionary All the keys in a dictionary can be accessed as a list phonebook.keys() [’Beth’, ’Alice’, ’Cecil’] All the values in a dictionary can be accessed as a list phonebook.values() [’9102’, ’2341’, ’3258’] The keys and values in a dictionary can be accessed as a list of tuples phonebook.items() [(’Beth’, ’9102’), (’Alice’, ’2341’), (’Cecil’, ’3258’)] Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-26-2048.jpg&f=jpg&w=240)





![Control Flow:The for loop #!/usr/bin/python names = [’Jaganadh’,’Biju’,’Sreejith’, ’Kenneth’,’Sundaram’] for name in names: print "Hello %s" %name Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-32-2048.jpg&f=jpg&w=240)









![Functions: Arbitrary Arguments def minimum(*args): res = args[0] for arg in args[1:]: if arg < res: res = arg return res print minimum(3,4,1,2,5) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-42-2048.jpg&f=jpg&w=240)










![Object Oriented Programming: Inheritance class Student(SchoolMember): ’’’Represents a student.’’’ def __init__(self, name, age, marks): SchoolMember.__init__(self, name, age) self.marks = marks print ’(Initialized Student: %s)’ % self.name def tell(self): SchoolMember.tell(self) print ’Marks: "%d"’ % self.marks t = Teacher(’Mrs. Shrividya’, 40, 30000) s = Student(’Swaroop’, 22, 75) members = [t, s] for member in members: member.tell() Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-53-2048.jpg&f=jpg&w=240)
![Modules A module is basically a file containing all your functions and variables that you have defined. To reuse the module in other programs, the filename of the module must have a .py extension. By using the import statement you can use built-in modules in Python import sys , os sys.argv[1] os.name os.curdir import math math.sqrt(9) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-54-2048.jpg&f=jpg&w=240)



![Handling Exceptions import sys try: f = open(myfile.txt) s = f.readline() i = int(s.strip()) except IOError as (errno, strerror): print "I/O error({0}): {1}".format(errno, strerror) except ValueError: print "Could not convert data to an integer." except: print "Unexpected error:", sys.exc_info()[0] raise Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-58-2048.jpg&f=jpg&w=240)





This document provides an introduction and overview of the Python programming language. It discusses Python's features such as being simple, easy to learn, free and open source, portable, and having batteries included. It also covers installing Python, writing a simple "Hello World" program, using variables and data types, operators, control flow statements, functions, and various Python data structures like lists, tuples, and dictionaries. The document is intended to teach beginners the basics of Python.















![Data Structure: List A list is a data structure that holds an ordered collection of items fruits = [’apple’,’banana’,’orange’] marks = [12,15,17] avgs = [1.5, 4.5,7.8] avgm = [1.5, 4.5,7.8,avgs] lists are mutable elemnts can be accessed by index numbers either positive index or negative index can be used to access elements Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-16-2048.jpg&f=jpg&w=240)
![Data Structure: List elemnts can be accessed by index numbers fruits[0] elements can be accessed with positive or negative index avgs[-1] new elements can be appended to a list fruits.append(’cherry’) list can be sorted or reversed fruits.sort() fruits.reverse() length of a list can be identified by the ’len’ function len(fruits) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-17-2048.jpg&f=jpg&w=240)
![Data Structure: List elements can be deleted del fruits[0] list can be sliced new list = fruits[1:3] lists can be extended flowers = [’rose’,’lilly’,’tulip’] fruits.extend(flowers) the index method can be used to find index of an item in a list fruits.index(’apple’) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-18-2048.jpg&f=jpg&w=240)
![Data Structure: List The pop method removes an element from a list fruits.pop() The remove method is used to remove the first occurrence of a value: flowers = [’rose’,’lilly’,’tulip’,’rose’] flowers.remove(’rose’) The reverse method reverses the elements in the list. flowers.reverse() The sort method is used to sort lists in place flowers.sort() Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-19-2048.jpg&f=jpg&w=240)
![Data Structure: List >>> numbers = [5, 2, 9, 7] >>> numbers.sort(cmp) >>> numbers [2, 5, 7, 9] >>> x = [’aardvark’, ’abalone’, ’acme’, ’add’, ’aerate’] >>> x.sort(key=len) >>> x [’add’, ’acme’, ’aerate’, ’abalone’, ’aardvark’] >>> x = [4, 6, 2, 1, 7, 9] >>> x.sort(reverse=True) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-20-2048.jpg&f=jpg&w=240)


![Data Structure: Dictionary Another useful data type built into Python is the dictionary Dictionaries are sometimes found in other languages as associative memories or associative arrays. Dictionaries consist of pairs (called items) of keys and their corresponding values phonebook = {’Alice’: ’2341’, ’Beth’: ’9102’, ’Cecil’: ’3258’} phonebook[’Alice’] #’2341’ Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-23-2048.jpg&f=jpg&w=240)
![Basic Dictionary Operations len(d) returns the number of items (key-value pairs) in d d = {’Alice’: ’2341’, ’Beth’: ’9102’, ’Cecil’: ’325 len(d) 3 d[’Alice’] returns the value associated with the key k ie ”2341” d[’Alice’] = ’456’ associates the value ’456’ with the key ’Alice’ del d[’Alice’] deletes the item with key ’Alice’ ’Alice’ in d checks whether there is an item in d that has the key ’Alice’ Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-24-2048.jpg&f=jpg&w=240)
![Data Structure: Dictionary Key types: Dictionary keys dont have to be integers (though they may be). They may be any immutable type, such as floating-point (real) numbers, strings, or tuples. Automatic addition: You can assign a value to a key, even if that key isnt in the dictionary to begin with; in that case, a new item will be created. You cannot assign a value to an index outside the lists range (without using append or something like that). phonebook[’Ravi’] = ’567’ Membership: The expression k in d (where d is a dictionary) looks for a key, not a value. ’Alice’ in phonebook Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-25-2048.jpg&f=jpg&w=240)
![Data Structure: Dictionary All the keys in a dictionary can be accessed as a list phonebook.keys() [’Beth’, ’Alice’, ’Cecil’] All the values in a dictionary can be accessed as a list phonebook.values() [’9102’, ’2341’, ’3258’] The keys and values in a dictionary can be accessed as a list of tuples phonebook.items() [(’Beth’, ’9102’), (’Alice’, ’2341’), (’Cecil’, ’3258’)] Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-26-2048.jpg&f=jpg&w=240)





![Control Flow:The for loop #!/usr/bin/python names = [’Jaganadh’,’Biju’,’Sreejith’, ’Kenneth’,’Sundaram’] for name in names: print "Hello %s" %name Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-32-2048.jpg&f=jpg&w=240)









![Functions: Arbitrary Arguments def minimum(*args): res = args[0] for arg in args[1:]: if arg < res: res = arg return res print minimum(3,4,1,2,5) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-42-2048.jpg&f=jpg&w=240)










![Object Oriented Programming: Inheritance class Student(SchoolMember): ’’’Represents a student.’’’ def __init__(self, name, age, marks): SchoolMember.__init__(self, name, age) self.marks = marks print ’(Initialized Student: %s)’ % self.name def tell(self): SchoolMember.tell(self) print ’Marks: "%d"’ % self.marks t = Teacher(’Mrs. Shrividya’, 40, 30000) s = Student(’Swaroop’, 22, 75) members = [t, s] for member in members: member.tell() Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-53-2048.jpg&f=jpg&w=240)
![Modules A module is basically a file containing all your functions and variables that you have defined. To reuse the module in other programs, the filename of the module must have a .py extension. By using the import statement you can use built-in modules in Python import sys , os sys.argv[1] os.name os.curdir import math math.sqrt(9) Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-54-2048.jpg&f=jpg&w=240)



![Handling Exceptions import sys try: f = open(myfile.txt) s = f.readline() i = int(s.strip()) except IOError as (errno, strerror): print "I/O error({0}): {1}".format(errno, strerror) except ValueError: print "Could not convert data to an integer." except: print "Unexpected error:", sys.exc_info()[0] raise Jaganadh G Let’s Learn Python](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fkonguworkshop-120427114946-phpapp02%2f75%2fLet-s-Learn-Python-An-introduction-to-Python-58-2048.jpg&f=jpg&w=240)



