Python NotesforProfessionals Chapter 29;Bosic Input and Output cten29. ing er Fcio Chapter40:StringFormatting Chapter 2:Python Data Types 800 pages ofprofessionalhints and tricks GoalKicker. Disclaimer This isanunofficial freebookcreated foreducationalpurposes and is FreeProgramming Books Alltrademarksandregistered trademarksare
Contents About Chapter 1: Getting started with Python Language 2 Section 11: Getting Storted 2 Section 12: Creating variobles and assigning volues Section 13: Block Indentation .. ...10 Section 1.4: Datatupes .... 11 Section 15: Collection Lypes 15 Section 16: IDLE - Puthon GUI .19 Section 17: User Input . 21 Section 18: Builtin Modules and Functions .21 Section 1.9: Creoting o module 25 Section 110. Instollation of Python 2.7.x ond 3.x 26 Section 111 String function - strO and reprQ 28 Section 112: Instaling externol modules using pip 29 Section 113: Help Utility 31 Chapter 2:Python DataTypes EE Section 21: String Data Type EE Section 2.2: Set Dato Types EE Section 2.3: Numbers dato type EE Section 2.4: List Dato Type 34 Section 2.5: Dictionary Dato Type .34 Section 2.6: Tuple Dato Tupe .34 Chapter3:Indentation 35 Section 3.1: Simple exomple 35 Section 3.2: How Indentotion is Parsed 35 Section 3.3: Indentation Errors .36 Chapter4:CommentsandDocumentation ..37 Section 4.1: Single line inline ond multiline ments 37 Section 4.2: Progrommaticolly accessing docstrings . 37 Section 4.3: Write documentation using docstrings 38 Chapter 5:Date and Time 42 Section 5.1: Parsing o string into o timezone oware dotetime object 42 Section 5.2: Constructing timezone-awore dotetimes 42 Section 5.3: Computing time dlifferences 44 Section 5.4: Bosic dotetime objects usoge 44 Section 5.5: Switching between time zones 45 Section 5.6: Simple dote orithmetic Section 5.7: Converting timestomp to clotetime Section 5.8: Subtracting months from a date occurotely Section 5.9: Parsing an arbitrory ISQ 8601 timestomp with minimol librories . 46 Section 5.10: Get an ISO 8601timestomp . ...47 Section 5.1l: Porsing o string with a short time zone nome into o timezone oware dotetime object 47 Section 5.12: Fuzzy dotetime parsing (extracting dotetime out of o text) 48 Section 5.13: lterate over dates .49 Chapter6:DateFormatting .50 Section 61: Time between two dote-times 50 Section 6.2: Outputting_ datetime object to string 50
Section 63: Parsing string to dotetime object .50 Chapter 7:Enum 51 Section Z.1: Creoting an enum (Puthon 2.4 through 33) 51 Section Z.2: terotion . 51 Chapter 8:Set ..52 Section 8.1: Qperotions on sets ... 52 Section 8.2: Get the unique elements of o list 53 Section 8.3: Set of Sets 53 Section 8.4: Set Qperations using Methods ond Builtins 53 Section 8.5: Sets versus multisets ... 55 Chapter9:SimpleMathematicalOperators 57 Section 9.t Division . 57 Section 9.2: Addition 58 Section 9.3: Exponentiotion 59 Section 9.4: Trigonometric Functions Section 9.5: Inplace Operations . Section 9.6: Subtraction .61 Section 9.7: Multiplicotion ...61 Section 9.8: Logorithms 62 Section 9.9: Modulus 62 Chapter10:BitwiseOperators Section 10.1: Bitwise NOT 65 Section 10.2: Bitwise XOR (Exclusive OR) 66 Section 10.3: Bitwise AND ....7 Section 10.4: Bitwise OR Section 10.5: Bitwise Left Shift 67 Section 10.6 Bitwise Right Shift ...68 Section 10.7: Inploce Qperations 68 Chapter11:Boolean Operators .69 Section ll1: ond' ond or are not guaranteed to return o booleon 69 Section 11.2: A simple exomple 69 Section 11.3: Short-circuit evoluotion Section.114. ond 70 Section 11.5: or . .70 Section 11.6: not .71 Chapter12:OperatorPrecedence .72 Section 12.1: Simple Qperotor Precedence Exomples in python ..72 Chapter13:VariableScopeandBinding Section 13.1: Nonlocol Voriobles 73 Section 13.2: Globol Voriobles Section 133: Locol Vaniobles 74 Section 13.4: The del mond 75 Section 13.5: Functions skip closs scope when looking up nomes 76 Section 13.6: Locol vs Globol Scope 77 Section 13.7: Binding Occurrence .79 Chapter14:Conditionals .80 Section 14.t Conditional Expression (or *The Ternory Operator) 80 Section 14.2: if elif ond else 80 Section 14.3: Truth Values 80
Section 14.4: Boolean Logic Expressions 81 Section 14.5: Using the cmp function to get the porison result of two objects Section 14.6: Else stotement 83 Section 14.7: Testing if an object is None and ossigning it .84 Section 14.8: If stotement ...84 Chapter 15:Comparisons ..86 Section 15.1: Chain Componisons - ..86 Section 15.2: Comporison by is vs '== ...87 Section 15.3: Greater thon or less thon 88 Section 15.4: Not equol to 88 Section 15.5: Equol To .. 89 Section 15.6: Comporing Objects .... . 89 Chapter16:Loops ... 91 Section 16.1: Breok ond Continue in Loops 91 Section 16.2: For loops 93 Section 16.3: Iteroting over lists Section 16.4: Loops with on "else" clause 94 Section 16.5: The Poss Stotement Section 16.6: Iterating over dictionaries ..97 Section 16.7: The "holf loop" do-while ..98 Section 16.8: Looping and Unpocking 98 Section 16.9: Iteroting different portion of o list with different step size Section 16.10: while Loop 100 Chapter17:Arrays 102 Section 171: Access individuol elements through indexes .102 Section 172: Bosic Introduction to Arraus 102 Section 173: Append ony volue to the orroy using appendQ method 103 Section 174: Insert volue in an orroy using insertO method 103 Section 17.5: Extend puthon orray using extendQ method 103 Section 176 Add items from list into arroy using fromlistO method 104 Section 17.7: Remove any arroy element using removeQ method 104 Section 17.8: Remove lost orray element using popQ method 104 Section 17.9: Fetch ony element through its index using index0 method ... 104 Section 1710: Reverse o python arroy using reverseQ method 104 Section 1Z.ll: Get arroy buffer informotion through buffer_ infoQ method 105 Section 1712: Check for number of occurrences of on element using countQ method ... 105 Section 1713: Convert orroy to string using tostringQ method 105 Section 17.14: Convert arroy to o python list with some elements using tolistO method 105 Section 17.15: Aopend o string to char array using fromstring0 method 105 Chapter 18: Multidimensional arrays 106 Section 18.1: Lists in lists 106 Section 18.2 Lists in lists in lists in. ... 106 Chapter19:Dictionary .108 Section 19.1: Introduction to Dictionory 108 Section 19.2: Avoiding KeyError Exceptions 109 Section 19.3: Iteroting Over a Dictionory .109 Section 19.4: Dictionory with defaulit volues ... .110 Section 19.5: Merqing dictionaries 111 Section 19.6: Accessing keys and values 111 Section 19.7: Accessing volues of o dictionory 112
Section 19.8: Creating a dictionary 112 Section 19.9: Creating an ordered dictionory .113 Section 19.10: Unpocking dictionories using the " operotor 113 Section 19.11 The trailing_.ma 114 Section 19.12: The dikctO constructor 114 Section 19.13: Dictionories Exomple -.. 114 Section 19.14: All binations of dictionory values 115 Chapter 20:List 117 Section 20.1: List methods ond supported operotors 117 Section 20.2: Accessing list values 122 Section 20.3: Checking if list is empty 123 Section 20.4: Iterating over o list ...... .123 Section 20.5: Checking whether on item is in o list .124 Section 20.6: Any and Al1 124 Section 20.7: Reversing list elements . 125 Section 20.8: Concatenate ond Merge lists 125 Section 20.9: Length of o list 126 Section 20.10: Remove duplicote volues in list 126 Section 20.11: Comparison of lists 127 Section 20.12: Accessing volues in nested list 127 Section 20.13: Initiolizing o List to o Fixed Number of Elements .128 Chapter 21:List prehensions 130 Section 211: List Comprehensions 130 Section 21.2: Conditional List Comprehensions 132 Section 21.3: Avoid repetiive ond expensive operations using conditiongl clouse 134 Section 21.4: Dictionory Comprehensions 135 Section 215: List Comprehensions with Nested Loops .136 Section 216_ Generotor Expressions 138 Section 21.7: Set Comprehensions 140 Section 21.8: Refactoring filter ond map to list prehensions 140 Section 21.9: Comprehensions involving tuples 141 Section 2110: Counting Occurrences Using Comprehension 142 Section 2lll: Chonging Tupes in o List 142 Section 2112: Nested List Comprehensions ... .142 Section 2113 Iterote two or more list simultoneously within list prehension 143 Chapter22:Listslicing(selecting partsoflists) ... 144 Section 22.1: Using the third "step argument .144 Section 22.2: Selecting o sublist from o list ... 144 Section 223: Reversing o list with slicing 144 Section 22.4: Shifting o list using slicing .144 Chapter23:groupbyQ - 146 Section 23.1: Exomple 4 .146 Section 23.2: Exomple 2 .146 Section 23.3: Exomple 3 147 Chapter 24:Linked lists 149 Section 24.1: Single linked list exomple ... 149 Chapter 25:Linked List Node 154 Section 25.1: Write o simple Linked List Node in puthon 154 Chapter26:Filter 155
Python Notes For Professionals(英文版).pdf
