
PYTHON PROGRAMMING Notes by Michael Brothers http://titaniumventures.net/library/ Table of Contents INTRODUCTION ...................................................................................................................................................................... 5 What is Python? ................................................................................................................................................................. 5 Ways to Code Python ......................................................................................................................................................... 5 Using Anaconda .................................................................................................................................................................. 5 Using Jupyter Notebooks ................................................................................................................................................... 5 Python 2 vs Python 3 .......................................................................................................................................................... 5 PEP 8 -- Style Guide for Python Code................................................................................................................................. 5 Using this guide: ................................................................................................................................................................. 5 PYTHON PROGRAMMING ...................................................................................................................................................... 6 Variables ............................................................................................................................................................................. 6 Multiple Declaration .......................................................................................................................................................... 6 Multiple Assignment .......................................................................................................................................................... 6 Data Types .......................................................................................................................................................................... 6 Operators ............................................................................................................................................................................ 6 Comparison Operators: ...................................................................................................................................................... 6 Chained Comparison Operators: ....................................................................................................................................... 6 Strings: ................................................................................................................................................................................ 7 Lists: .................................................................................................................................................................................... 7 Tuples: ................................................................................................................................................................................. 7 Dictionaries: ........................................................................................................................................................................ 7 Sets:..................................................................................................................................................................................... 7 Comments:.......................................................................................................................................................................... 7 WORKING WITH STRINGS ...................................................................................................................................................... 8 Built-in String Functions: .................................................................................................................................................... 8 Built-in String Methods: ..................................................................................................................................................... 8 Splitting Strings: ................................................................................................................................................................. 8 Joining Strings: .................................................................................................................................................................... 8 Turning Objects Into Strings ............................................................................................................................................... 8 String formatting with formatted string literals (f-strings) ............................................................................................... 9 String Formatting with .format() ..................................................................................................................................... 10 String Formatting with Placeholders: .............................................................................................................................. 11 Escape Characters: ........................................................................................................................................................... 11 WORKING WITH LISTS: ......................................................................................................................................................... 12 Built-in List Functions: ...................................................................................................................................................... 12 Built-in List Methods: ....................................................................................................................................................... 12 Adding & Removing List Items ......................................................................................................................................... 12 List Index Method ............................................................................................................................................................. 12 Sorting Lists....................................................................................................................................................................... 13 Making a List of Lists: ....................................................................................................................................................... 13 LIST COMPREHENSIONS ....................................................................................................................................................... 14 WORKING WITH TUPLES ...................................................................................................................................................... 15 WORKING WITH DICTIONARIES ........................................................................................................................................... 15 Dictionary Comprehensions: ............................................................................................................................................ 15 WORKING WITH SETS: .......................................................................................................................................................... 16 Set Operators .................................................................................................................................................................... 16 1 REV 1020 Built-in Set Methods ........................................................................................................................................................ 16 Frozensets ......................................................................................................................................................................... 16 RANGE ................................................................................................................................................................................... 16 CONDITIONAL STATEMENTS & LOOPS ................................................................................................................................ 17 If / Elif / Else statements: ................................................................................................................................................. 17 For Loops .......................................................................................................................................................................... 17 While Loops ...................................................................................................................................................................... 17 Nested Loops .................................................................................................................................................................... 17 Loop Control Statements (Break, Continue, Pass
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages56 Page
-
File Size-