Python Syntax
- Data Type
- Indention
- Math Operation
- Comment
String and console output
- 转移字符\
- Access by index
- Strig Method
- str()
- Not Notation
- Printing Strings
- print variables
Advanced printing
- string concatenation
- explicit string conversion
- string formatting with %
Review
- string creating, three way: ”, ” “, str()
- string method: upper(), lower()
- print string
Datetime
- datetime.now
- now.year
- hot date
- pretty date
Conditionals and flow control
- booleans
- comparison operator
- boolean operator, not first, and next, or last
- if, else,elif
Summary: comparator, boolean operator, conditional statement
Functions
- Function Junctions
- Calling Function
- Agruments
- Function calling Functions
- import
- built in functions
List and Dictionary
list
- Access by index
- Assignment
- Late arrival(append) and list length
- Slicing
- Search and insert
- For one and all
- sort
Dictionary
- key accessing
- new entries
- del by keyword (general cases)
- remove by value (list notation method)
operation with list
- list as argument
- string looping
Lists and funcstions
- .pop(index),.remove(item)
- range
- iterating a list in a function
- using string in list in function
Battleship exercise
- ” “.join(letters)
- from random import randint
Loops
- while loop
- for strings
- for list
- for dictionary
- eumuerate
- zip
Practice
- Fun with numbers
- String it together(access, reverse, split and join)
- Listing your problems
- remove duplicates
Advanced Python Features
- items(),values(),keys()
- list comprehension using for/in and if
- list slicing
- reverse a list, lst[::-1]
- Anonymous Functions lambda x: x%3 ==0
- Filter, filter(lambda, lst)
bitwise operation
- << and >>
- &
- |
- ^
- 0b101, bin(0b101)
Classes
To be sepcified
- Class basics: class NewName(object):
- Class instance
- Class member variable : belongs to class
- Calling member variables
- Initializing a class: __init__
- Member function
- Overloading
File input/Output
- f = open(“text.txt”,’r’) : ‘r’,’w’,’r+’,’a’
- f.close()
- with open(‘text.txt’,’w’) as f: ….. it will close the file for us
- f.closed
- f.readline() read text line-by-line