2018-09-18 CS61A Lab1

Lab1

  1. git配置:今天學習之前,先把代碼git上,按照這個以後每天都更新一下git^^

    • 遇到問題:remote的時候我寫錯了網址,那就remote刪除,再重新remote新的地址

       ```		git remote remove origin 		```
      
  2. print和return的引號
    print(‘Hello World!’) 輸出無引號,引號只是print寫法 return ‘Exiting this function.’ return內容包括引號

  3. python的與或非 and or not() Python 值爲FALSE情況:

     ① 0
     ② None 
     ③'' (the empty string) 
     ④ [] (the empty list)
     
     >>>True and 13 竟然爲13 (A and B,A是True的話,結果就是B)
     >>>1 and 2 and 3 and 4 結果爲4,1是True就由後面決定,以此類推
     **python只要提前知道結果,就不會繼續判斷了**
    
  4. error信息,debug能力很重要,看得懂報錯信息
    | Error Types | Descriptions |
    | -------- | ----- |
    | SyntaxError 語法錯誤 | Contained improper syntax (如少了冒號,括號,引號)
    |
    | IndentationError 縮進錯誤 | Contained improper indentation (python縮進很嚴格) |
    | TypeError 類型錯誤 | Attempted operation on incompatible types (如不同類型無法相加) 或者調用函數時參數不正確 |
    |ZeroDivisionError |Attempted division by zero除零|

  5. python bool(-1)是TRUE,一直以爲是fasle,所有非零都爲真,cpp也是如此

  6. 人家寫的比我簡潔

    total, stop = 1, n-k
    while n > stop:
        total, n = total*n, n-1
    return total
  1. python3 -m doctest “filename” 真的很好用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章