×
MY GOAL IS TO PAY BACK MY PARENTS
--Your friends at LectureNotes
Close

Note for Python Programming - PY by Nihar Ranjan Rout

  • Python Programming - PY
  • Note
  • Lovely Professional University - LPU
  • Computer Science Engineering
  • B.Tech
  • 3 Topics
  • 370 Views
  • 8 Offline Downloads
  • Uploaded 1 year ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-3

Table of Contents About the Tutorial .......................................................................................................................................... i Audience ........................................................................................................................................................ i Prerequisites .................................................................................................................................................. i Disclaimer & Copyright................................................................................................................................... i Table of Contents .......................................................................................................................................... ii 1. PYTHON ─ OVERVIEW ............................................................................................................... 1 History of Python .......................................................................................................................................... 1 Python Features ............................................................................................................................................ 1 2. PYTHON ─ ENVIRONMENT........................................................................................................ 3 Local Environment Setup............................................................................................................................... 3 Getting Python .............................................................................................................................................. 3 Installing Python ........................................................................................................................................... 4 Setting up PATH ............................................................................................................................................ 5 Setting path at Unix/Linux ............................................................................................................................ 5 Setting path at Windows ............................................................................................................................... 6 Python Environment Variables ...................................................................................................................... 6 Running Python ............................................................................................................................................. 6 3. PYTHON ─ BASIC SYNTAX .......................................................................................................... 9 First Python Program .................................................................................................................................... 9 Python Identifiers........................................................................................................................................ 10 Python Keywords ........................................................................................................................................ 11 Lines and Indentation.................................................................................................................................. 11 Multi-Line Statements ................................................................................................................................. 13

Text from page-4

Quotation in Python .................................................................................................................................... 13 Comments in Python ................................................................................................................................... 14 Using Blank Lines ........................................................................................................................................ 14 Waiting for the User .................................................................................................................................... 15 Multiple Statements on a Single Line .......................................................................................................... 15 Multiple Statement Groups as Suites .......................................................................................................... 15 Command Line Arguments .......................................................................................................................... 15 Accessing Command-Line Arguments .......................................................................................................... 16 Parsing Command-Line Arguments ............................................................................................................. 17 getopt.getopt method ................................................................................................................................. 17 Exception getopt.GetoptError ..................................................................................................................... 17 4. PYTHON ─ VARIABLE TYPES .................................................................................................... 20 Assigning Values to Variables ...................................................................................................................... 20 Multiple Assignment ................................................................................................................................... 21 Standard Data Types ................................................................................................................................... 21 Python Numbers ......................................................................................................................................... 21 Python Strings ............................................................................................................................................. 23 Python Lists ................................................................................................................................................. 24 Python Tuples ............................................................................................................................................. 24 Python Dictionary ....................................................................................................................................... 26 Data Type Conversion ................................................................................................................................. 27 5. PYTHON ─ BASIC OPERATORS ................................................................................................. 29 Types of Operators ...................................................................................................................................... 29 Python Arithmetic Operators ...................................................................................................................... 29 Python Comparison Operators .................................................................................................................... 31

Text from page-5

Python Assignment Operators .................................................................................................................... 34 Python Bitwise Operators ........................................................................................................................... 36 Python Logical Operators ............................................................................................................................ 38 Python Membership Operators ................................................................................................................... 38 Python Identity Operators........................................................................................................................... 40 Python Operators Precedence ..................................................................................................................... 41 6. PYTHON ─ DECISION MAKING................................................................................................. 44 If Statement ................................................................................................................................................ 45 If…else Statement ....................................................................................................................................... 46 The elif Statement ....................................................................................................................................... 48 Single Statement Suites ............................................................................................................................... 49 7. PYTHON ─ LOOPS ................................................................................................................... 51 While Loop .................................................................................................................................................. 52 The Infinite Loop ......................................................................................................................................... 53 Using else Statement with Loops ................................................................................................................ 54 Single Statement Suites ............................................................................................................................... 55 For Loop ...................................................................................................................................................... 56 Iterating by Sequence Index ........................................................................................................................ 57 Using else Statement with Loops ................................................................................................................ 58 Nested Loops .............................................................................................................................................. 59 Loop Control Statements............................................................................................................................. 60 Break Statement ......................................................................................................................................... 61 Continue Statement .................................................................................................................................... 63 Pass Statement ........................................................................................................................................... 65

Text from page-6

8. PYTHON ─ NUMBERS .............................................................................................................. 66 Number Type Conversion ............................................................................................................................ 67 Random Number Functions ......................................................................................................................... 69 Trigonometric Functions ............................................................................................................................. 69 Mathematical Constants ............................................................................................................................. 70 9. PYTHON ─ STRINGS................................................................................................................. 71 Accessing Values in Strings .......................................................................................................................... 71 Updating Strings .......................................................................................................................................... 71 Escape Characters ....................................................................................................................................... 72 String Special Operators .............................................................................................................................. 73 String Formatting Operator ......................................................................................................................... 74 Triple Quotes .............................................................................................................................................. 76 Unicode String ............................................................................................................................................. 77 Built-in String Methods ............................................................................................................................... 78 capitalize() Method ..................................................................................................................................... 82 center(width, fillchar) Method .................................................................................................................... 82 count(str, beg= 0,end=len(string)) Method ................................................................................................. 83 decode(encoding='UTF-8',errors='strict') Method ....................................................................................... 84 encode(encoding='UTF-8',errors='strict') Method ....................................................................................... 85 endswith(suffix, beg=0, end=len(string)) Method ....................................................................................... 86 expandtabs(tabsize=8) ................................................................................................................................ 87 find(str, beg=0 end=len(string)) ................................................................................................................... 88 index(str, beg=0, end=len(string)) ............................................................................................................... 89 isalnum() Method ....................................................................................................................................... 90 isalpha() ...................................................................................................................................................... 90

Lecture Notes