1. 程式人生 > >上節內容回顧和補充

上節內容回顧和補充

上節內容回顧和補充

    程式語言
        高階
        低階
        
    Python種類
        JavaPython
        cPython    *****
        pypy
        
        位元組碼 和 機器碼
        
    Python程式:
        1. 
            終端:
                C:\python35\python.exe D:\1.py
            直譯器:
                C:\python35\python.exe 
                
        
2. 檔案形 #/usr/bin/u/ubv/a python python 1.py ./1.py 加許可權 3. 編碼 #/usr/bin/u/ubv/a python # -*- coding:utf-8 -*- 補充: 位元組,位 unicode utf8 gbk utf8:
3 gbk : 2 4. print("sdf") 5. inp = input('>>>') PS: >>> hello inp = "hello" >>> 10 inp = "10" #
如果將字串轉換成數字 new_inp = int(inp) inp * 10 =????? 6. 變數名 字母 數字 下劃線 要求: 不能數字開頭 不能使用關鍵字 建議不要用python內建的。。。。 7. 條件語句 1. 基本 2. 巢狀 3. if elif else ... 8. while迴圈 while 條件: .... print('...') 補充: a. while else b. continue break continue ,終止當前迴圈,開始下一次迴圈 break ,終止所有迴圈 使用者登陸(三次機會重試) count = 0 while count < 3: user = input('>>>') pwd = input('>>>') if user == 'alex' and pwd == '123': print('歡迎登陸') print('..........') break else: print('使用者名稱或者密碼錯誤') count = count + 1 今日內容: python開發IDE: pycharm、eclipse # 專業版 # 不要漢化 1、運算子 結果是值 算數運算 a = 10 * 10 賦值運算 a = a + 1 a+=1 結果是布林值 比較運算 a = 1 > 5 邏輯運算 a = 1>6 or 1==1 成員運算 a = "" in "鄭建文" 2、基本資料型別 數字 int ,所有的功能,都放在int裡 a1 = 123 a1 = 456 - int 將字串轉換為數字 a = "123" print(type(a),a) b = int(a) print(type(b),b) num = "0011" v = int(num, base=16) print(v) - bit_lenght # 當前數字的二進位制,至少用n位表示 r = age.bit_length() 字串 str s1 = "asdf" s2 = "asdffas" # test = "aLex" # 首字母大寫 # v = test.capitalize() # print(v) # 所有變小寫,casefold更牛逼,很多未知的對相應變小寫 # v1 = test.casefold() # print(v1) # v2 = test.lower() # print(v2) # 設定寬度,並將內容居中 # 20 代指總長度 # * 空白未知填充,一個字元,可有可無 # v = test.center(20,"中") # print(v) # 去字串中尋找,尋找子序列的出現次數 # test = "aLexalexr" # v = test.count('ex') # print(v) # test = "aLexalexr" # v = test.count('ex',5,6) # print(v) # # encode # decode # 以什麼什麼結尾 # 以什麼什麼開始 # test = "alex" # v = test.endswith('ex') # v = test.startswith('ex') # print(v) # # test = "12345678\t9" # v = test.expandtabs(6) # print(v,len(v)) # 從開始往後找,找到第一個之後,獲取其未知 # > 或 >= # test = "alexalex" # 未找到 -1 # v = test.find('ex') # print(v) # index找不到,報錯 忽略 # test = "alexalex" # v = test.index('8') # print(v) # 格式化,將一個字串中的佔位符替換為指定的值 # test = 'i am {name}, age {a}' # print(test) # v = test.format(name='alex',a=19) # print(v) # test = 'i am {0}, age {1}' # print(test) # v = test.format('alex',19) # print(v) # 格式化,傳入的值 {"name": 'alex', "a": 19} # test = 'i am {name}, age {a}' # v1 = test.format(name='df',a=10) # v2 = test.format_map({"name": 'alex', "a": 19}) # 字串中是否只包含 字母和數字 # test = "123" # v = test.isalnum() # print(v) 列表 list ... 元祖 tuple ... 字典 dict ... 布林值 bool ...