Embed presentation
Downloaded 50 times




![Reading Keyboard Input• Python provides two built-in functions to read a line of text fromstandard input, which by default comes from the keyboard. Thesefunctions are −• raw_input• input• The raw_input Function• The raw_input([prompt]) function reads one linefrom standard input and returns it as a string(removing the trailing newline).str = raw_input("Enter your input: ");print "Received input is : ", str](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-5-2048.jpg&f=jpg&w=240)
![• The input Function• The input([prompt]) function is equivalent toraw_input, except that it assumes the input is avalid Python expression and returns the evaluatedresult to you.str = input("Enter your input: ");print "Received input is : ", str](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-6-2048.jpg&f=jpg&w=240)






![Strings• Set of characters represented in the quotation marks.Python allows for either pairs of single or double quotes• 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 5th• print str[2:] # Prints string starting from 3rd character• print str * 2 # Prints string two times• print str + "TEST" # Prints concatenated string](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-13-2048.jpg&f=jpg&w=240)
![Python Lists• A list contains items separated by commas and enclosed withinsquare brackets ([]). To some extent, lists are similar to arrays in C.One difference between them is that all the items belonging to alist can be of different data type.• list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]ls = [123, 'john']• print list # Prints complete list• print list[0] # Prints first element of the list• print list[1:3] # Prints elements starting from 2nd till 3rd• print list[2:] # Prints elements starting from 3rd element• print ls * 2 # Prints list two times• print list + ls # Prints concatenated lists](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-14-2048.jpg&f=jpg&w=240)
![Python Lists• Add elements to a list1. mylist.append(10)2. mylist.extend(["Raju",20,30])3. mylist.insert(1,"Ammu")• Search within lists -mylist.index('Anu’)• Delete elements from a list - mylist.remove(20)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-15-2048.jpg&f=jpg&w=240)

![Basic list operationsLength - lenConcatenation : +Repetition - ['Hi!'] * 4Membership - 3 in [1, 2, 3]Iteration- for x in [1, 2, 3]: print x,](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-17-2048.jpg&f=jpg&w=240)
![Sorting an array - list.sort()fruits = ["lemon", "orange", "banana", "apple"]print fruitsfruits.sort()for i in fruits:print iprint "nnnReverse ordernnn"fruits.sort(reverse=True)for i in fruits:print i](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-18-2048.jpg&f=jpg&w=240)
![Python Tuples• A tuple consists of a number of values separated bycommas. Tuples are enclosed within parentheses.• The main differences between lists and tuples are:Lists are enclosed in brackets ( [ ] ) and theirelements and size can be changed, while tuples areenclosed in parentheses ( ( ) ) and cannot beupdated.• read-only lists](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-19-2048.jpg&f=jpg&w=240)
![Tuple Example• tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )• tinytuple = (123, 'john')• print tuple # Prints complete list• print tuple[0] # Prints first element of the list• print tuple[1:3] # Prints elements starting from 2nd till 3rd• print tuple[2:] # Prints elements starting from 3rd element• print tinytuple * 2 # Prints list two times• print tuple + tinytuple # Prints concatenated lists](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-20-2048.jpg&f=jpg&w=240)

![Python Dictionary• Python's dictionaries are kind of hash table type.They work like associative arrays or hashes found inPerl and consist of key-value pairs• Dictionaries are enclosed by curly braces ({ }) andvalues can be assigned and accessed using squarebraces ([]).](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-22-2048.jpg&f=jpg&w=240)
![Example• dict = {}• dict['one'] = "This is one"• dict[2] = "This is two"• tinydict = {'name': 'john','code':6734, 'dept': 'sales'}• print dict['one'] # Prints value for 'one' key• print dict[2] # Prints value for 2 key• print tinydict # Prints complete dictionary• print tinydict.keys() # Prints all the keys• print tinydict.values() # Prints all the values](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-23-2048.jpg&f=jpg&w=240)
![Python Functions• Function blocks begin with the keyword def followedby the function name and parentheses ( ( ) ).• Any input parameters or arguments should be placedwithin these parentheses.• The first statement of a function can be an optionalstatement - the documentation string of the function ordocstring..• The statement return [expression] exits a function,optionally passing back an expression to the caller. Areturn statement with no arguments is the same asreturn None.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-24-2048.jpg&f=jpg&w=240)



![• Opening and Closing Files• The open Functionfile object = open(file_name [, access_mode][, buffering])• file_name: The file_name argument is a string value thatcontains the name of the file that you want to access.• access_mode: The access_mode determines the mode inwhich the file has to be opened, i.e., read, write, append,etc.• The close() MethodThe close() method of a file object flushes any unwritteninformation and closes the file object, after which no morewriting can be done.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-28-2048.jpg&f=jpg&w=240)


















The document provides an introduction to programming in Python. It discusses how Python can be used for web development, desktop applications, data science, machine learning, and more. It also covers executing Python programs, reading keyboard input, decision making and loops in Python, standard data types like numbers, strings, lists, tuples and dictionaries. Additionally, it describes functions, opening and reading/writing files, regular expressions, and provides examples of SQLite database connections in Python projects.




![Reading Keyboard Input• Python provides two built-in functions to read a line of text fromstandard input, which by default comes from the keyboard. Thesefunctions are −• raw_input• input• The raw_input Function• The raw_input([prompt]) function reads one linefrom standard input and returns it as a string(removing the trailing newline).str = raw_input("Enter your input: ");print "Received input is : ", str](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-5-2048.jpg&f=jpg&w=240)
![• The input Function• The input([prompt]) function is equivalent toraw_input, except that it assumes the input is avalid Python expression and returns the evaluatedresult to you.str = input("Enter your input: ");print "Received input is : ", str](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-6-2048.jpg&f=jpg&w=240)






![Strings• Set of characters represented in the quotation marks.Python allows for either pairs of single or double quotes• 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 5th• print str[2:] # Prints string starting from 3rd character• print str * 2 # Prints string two times• print str + "TEST" # Prints concatenated string](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-13-2048.jpg&f=jpg&w=240)
![Python Lists• A list contains items separated by commas and enclosed withinsquare brackets ([]). To some extent, lists are similar to arrays in C.One difference between them is that all the items belonging to alist can be of different data type.• list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]ls = [123, 'john']• print list # Prints complete list• print list[0] # Prints first element of the list• print list[1:3] # Prints elements starting from 2nd till 3rd• print list[2:] # Prints elements starting from 3rd element• print ls * 2 # Prints list two times• print list + ls # Prints concatenated lists](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-14-2048.jpg&f=jpg&w=240)
![Python Lists• Add elements to a list1. mylist.append(10)2. mylist.extend(["Raju",20,30])3. mylist.insert(1,"Ammu")• Search within lists -mylist.index('Anu’)• Delete elements from a list - mylist.remove(20)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-15-2048.jpg&f=jpg&w=240)

![Basic list operationsLength - lenConcatenation : +Repetition - ['Hi!'] * 4Membership - 3 in [1, 2, 3]Iteration- for x in [1, 2, 3]: print x,](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-17-2048.jpg&f=jpg&w=240)
![Sorting an array - list.sort()fruits = ["lemon", "orange", "banana", "apple"]print fruitsfruits.sort()for i in fruits:print iprint "nnnReverse ordernnn"fruits.sort(reverse=True)for i in fruits:print i](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-18-2048.jpg&f=jpg&w=240)
![Python Tuples• A tuple consists of a number of values separated bycommas. Tuples are enclosed within parentheses.• The main differences between lists and tuples are:Lists are enclosed in brackets ( [ ] ) and theirelements and size can be changed, while tuples areenclosed in parentheses ( ( ) ) and cannot beupdated.• read-only lists](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-19-2048.jpg&f=jpg&w=240)
![Tuple Example• tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )• tinytuple = (123, 'john')• print tuple # Prints complete list• print tuple[0] # Prints first element of the list• print tuple[1:3] # Prints elements starting from 2nd till 3rd• print tuple[2:] # Prints elements starting from 3rd element• print tinytuple * 2 # Prints list two times• print tuple + tinytuple # Prints concatenated lists](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-20-2048.jpg&f=jpg&w=240)

![Python Dictionary• Python's dictionaries are kind of hash table type.They work like associative arrays or hashes found inPerl and consist of key-value pairs• Dictionaries are enclosed by curly braces ({ }) andvalues can be assigned and accessed using squarebraces ([]).](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-22-2048.jpg&f=jpg&w=240)
![Example• dict = {}• dict['one'] = "This is one"• dict[2] = "This is two"• tinydict = {'name': 'john','code':6734, 'dept': 'sales'}• print dict['one'] # Prints value for 'one' key• print dict[2] # Prints value for 2 key• print tinydict # Prints complete dictionary• print tinydict.keys() # Prints all the keys• print tinydict.values() # Prints all the values](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-23-2048.jpg&f=jpg&w=240)
![Python Functions• Function blocks begin with the keyword def followedby the function name and parentheses ( ( ) ).• Any input parameters or arguments should be placedwithin these parentheses.• The first statement of a function can be an optionalstatement - the documentation string of the function ordocstring..• The statement return [expression] exits a function,optionally passing back an expression to the caller. Areturn statement with no arguments is the same asreturn None.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-24-2048.jpg&f=jpg&w=240)



![• Opening and Closing Files• The open Functionfile object = open(file_name [, access_mode][, buffering])• file_name: The file_name argument is a string value thatcontains the name of the file that you want to access.• access_mode: The access_mode determines the mode inwhich the file has to be opened, i.e., read, write, append,etc.• The close() MethodThe close() method of a file object flushes any unwritteninformation and closes the file object, after which no morewriting can be done.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprogramminginpythonbytijithomas-171208004450%2f75%2fProgramming-in-Python-28-2048.jpg&f=jpg&w=240)
















