0.GUI (graphical user interface) such as file finders eg sed 's/dude/Colt/g' report.txt > report_new.txt //sed:search and pop it to report_new Be familiar and confortable with command line file structure is a tree, all relative to a base ROOT director root/ each additional level down adds a "/" absolute path /Users/colt // abs path always start with a / --which stands for the root by default is at home directory and represent as "~" pwd : print working directory cd : change directory type python3 to go into python3, otherwise is python --2 use touch to create a new .py file print("hello world") //don't need the semi colon at end 1.variables must stary with a letter or underscore_ CASE sensitive!! 2. ** power % remainder / 䏿¯æ´æ°é¤æ³ï¼å°±æ¯æ£å¸¸çé¤ ï¼in python 3ï¼ python2 å c++䏿 ·è¿æ¯æ´æ°é¤æ³ x = 1 + 2**3/4*5 print(x) //1+8/4 *5 =1+2*5 =11.0 1+1.0 // 2.0 - to float automatically // --- Interger Division 5//3 #1 10//3 #3 (always round down) 1/2 #0.5 python always get float 2**3 #8 49**0.5 #7 13%2 #1 3.constans:fixed vlues such as numbers, letters and strings are constants string constants use single quotes ('') or double quotes ("") 4. try/except -- traceback try éé¢ä»»æä¸ä¸ªdieäºç´æ¥èµ°exceptï¼ä¸ä¼ç»§ç»èµ°ä¸é¢çäº--å©ç¨tryæ¥å°è¯å±é©ï¼catch errors astr = âhello bob' try: ister = int (astr) except: ister = -1 // usualy provide hints for where is wrong, can add a quit here 5. name = input('who are u?) // the input() will return a string print ('welcome', name) // the comma will creat a space 6. use # for comments in python 7. python use indent to distinguish block, which is 4 spaces, it is better to use space than tab, to avoid difference between different editors 8. python éçprintï¼ï¼ æèªå¨æ¢è¡åæ use --type(9) will show the type of it, can be a variable name 9. python documentation ---docs.python.org Give you information about python stuff--make sure to check the python3 documents ''' for python multiple line comments #the naming convention of python is s_n_a_k_e #you don't need to declare the type of variables nums_of_casts = 99 nums_of_casts * 2 #nums_of_cats doesn't change all, at, once = 5, 10, 15 #you can always assign and reassign variables 10. naming_conventions in python most variables should be lower case, CAPITAL_NAME usually is constants UpperCamelCase : refer to a class "dunder" for double underscore *** 11.Some data types: bool (True, False, the first case has to be capital) int str (a sequence of Unicode charsï¼ â â or ââ) listï¼an ordered sequence of values of other data types [1,2,3]) dict ( a collection of key: values e.g. {"first_name":"Le", "last_name": "Lei"} 12. Dynamic typing you can reassign variables to different types dynamic typing vs statically-typed(variables are stuck with their originally-assigned types) 13. None (case sensitive!) (python version of NULL) can set new stuff with None if we haven't assign it (want a container, but nothing here, and the type of None is Nonetype--only itself) 14.Declaring strings doesn't matter if single or double, but better to stay it consistant msg = "he said "hello there !"" --- error, python read it "XX" +YY"" msg2 = "he said 'hello there !'" --- good msg3 = 'he said "hello there !"' --- good 15.escape sequence str_sth = "he said \"ha ha\"" --- good #str is never a good variable name, which you could.. 16. string concateration with â +â user = "blue Boy" print("hello there" + user) # hello therebuleBoy ---ä¸ä¼èªå¨ç»ä½ å ç©ºæ ¼ 8 + "hello" #error! guess = 9 print("your guess is" + guess) #error! name = "col" name += "S" # name now = colS #also works for numbers 17.string format interpolate #æå ¥ f-strings (python 3.6+) x = 10 formatted = f"I told you {x} times!" #ä¸å¯ä»¥å¿äºè¿ä¸ªfï¼ #you can also do math in the {} # in python 2 .format() --play ground only support it print("the {} is ).format(sth) first = "Colt" last = "Steele" formatted = "First Name: {}, Last Name: {}". format(first, last) #å¯ä»¥ç´æ¥å¨string åå 18. every stirng is indexed, started with 0 "lol"[0] #l name = "Chuck" name[5] # error! max index is 4 ; not counting '\0' (if there is one in python) name[-1] #k name[-2] #c åçæ°çå· 19. convert data types in string interpolation, data type are implicitly converted into string form you can explicitly convert type by var2 = type (var1) deci = 12.213 interger = int(deci) #12 my_list = [1,2,3] my_list_as_string = string(my_list) # "[1,2,3]" 1/3 ----0.3333 int(99.99) #99 only truncate not around 4/2 ----2.0 round(thing to round, how many decimal points) 20.for input function, ä¸ä¼èªå¨æ¢è¡ data = input("what is your name?") # what is your name?your_input (also no space!) print("You said" +data) #onther way looks nicer print("what is your name?") data = input() # what is your name? -another line- your_input print("You said" +data) 21. conditional statements if name == "tony stark : use indent to distinguish print("you are Iron Man") elif name == "Peter Parker": #you can have multiple elif, but only one else print("you are Spider Man") elif name == "Natasha": print("you are Black Widom") elif name == "Thor": print("you are Thor") else : print("you are Norm Man") ------ #è¿ç§æ²¡æä¹åçå 容ï¼indentçè¯ä¼æ¥éï¼ if name == "tony stark : print("you are Iron Man") 22. Truthiness things are natually false: empty objects, empty strings, None, and zero animal = input("say sth) if animal: #没æinputæ¶èªå¨ä¸ä¼åè¿äº print("you said sth) == test if they have the same value "A" < "a" # yep logical operators: and, or(binary), not(unary) age > 2 and age < 8 if not isWeekend(): do th if not x or y: #å 夿not Xï¼ åç or do th 23.is vs == is check with the memory and == checks value is--checking equality a = 1 a == 1 #True a is 1 #True a = [1,2,3] b = [1,2,3] a == b #True a is b #Flase, they are different objects c = b b is c #True, b and c are pointing to the same stuff a = 13 b = 13 a == b #True a is b #True 24. loop -iterable objects [40,30,435] "hello' range(1,10) # generate 1-9 å å·¦ä¸å å³ for item in iterable_object: do sth with item eg: for char in "hello": print(char *10) #æ¯ä¸ªchar ä¼print 10 次 for x in rang(1,10): print x # print 1-9, BTW, python çprintä¼èªå¨æ¢è¡ 25. ranges ï¼commonly use for for loopsï¼ range (7) # 0-6 range(1,8) #1-7 æ°¸è¿æå³ä¾§çä¸å range(1,10,2) # give odd 1,3,5,7,9 - the last one is é´è· range(7,0,-1) #7-1 list(range(10)) #ok tricky: >>> nums = range(1,5) >>> print(nums) #range(1, 5) 26. while loop while bool_expression: do sth for num in range(1,11): print(num) <=> num = 1 while num < 11: num += 1 print(num) 27.break to exit out of a loop immediatly 28. style for python: PEP8(style Guide for python code!) autopep 8 --inplace ugly_code.py (need to install the package)