• Document: Python Practice Book. Release Anand Chitipothu
  • Size: 272.25 KB
  • Uploaded: 2018-11-27 12:38:59
  • Status: Successfully converted


Some snippets from your converted document:

Python Practice Book Release 2014-08-10 Anand Chitipothu June 03, 2016 Contents 1 About this Book 3 2 Table of Contents 5 2.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2 Working with Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.4 Object Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 2.5 Iterators & Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.6 Functional Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3 License 55 i ii Python Practice Book, Release 2014-08-10 Welcome to Python Practice Book. Contents 1 Python Practice Book, Release 2014-08-10 2 Contents CHAPTER 1 About this Book This book is prepared from the training notes of Anand Chitipothu. Anand conducts Python training classes on a semi-regular basis in Bangalore, India. Checkout out the upcoming trainings if you are interested. 3 Python Practice Book, Release 2014-08-10 4 Chapter 1. About this Book CHAPTER 2 Table of Contents 2.1 Getting Started 2.1.1 Running Python Interpreter Python comes with an interactive interpreter. When you type python in your shell or command prompt, the python interpreter becomes active with a >>> prompt and waits for your commands. $ python Python 2.7.1 (r271:86832, Mar 17 2011, 07:02:35) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> Now you can type any valid python expression at the prompt. python reads the typed expression, evaluates it and prints the result. >>> 42 42 >>> 4 + 2 6 Problem 1: Open a new Python interpreter and use it to find the value of 2 + 3. 2.1.2 Running Python Scripts Open your text editor, type the following text and save it as hello.py. print "hello, world!" And run this program by calling python hello.py. Make sure you change to the directory where you saved the file before doing it. anand@bodhi ~$ python hello.py hello, world! anand@bodhi ~$ Text after # character in any line is considered as comment. # This is helloworld program # run this as: # python hello.py print "hello, world!" Problem 2: Create a python script to print hello, world! four times. Problem 3: Create a python script with the following text and see the output. 5 Python Practice Book, Release 2014-08-10 1 + 2 If it doesn’t print anything, what changes can you make to the program to print the value? 2.1.3 Assignments One of the building blocks of programming is associating a name to a value. This is called assignment. The associated name is usually called a variable. >>> x = 4 >>> x * x 16 In this example x is a variable and it’s v

Recently converted files (publicly available):