1. 程式人生 > >Python全棧之路Day15

Python全棧之路Day15

-m 浮點型 tabs git 浮點 unicode 羅馬 整形 pen

初次編輯2017年10月4日 17:19:34

摘要
一. Python編碼(一)
二. 基礎語法回顧
作業
今日總結

摘要

引用:百度

一. Python編碼(一)

  1. 文本編輯器存儲流程
    1. 明文轉換成Unicode(存在內存上)
    2. Unicode轉換成Utf-8(存在硬盤上)
  2. 文本編輯器讀取流程
    1. Utf-8(存在硬盤上的)轉換成Unicode
    2. Unicode轉換成明文
  3. Python編輯器
    1. python 2.x
      1. str:bytes 數據
      2. Unicode:Unicode編碼後的二進制數據
    2. python 3.x
      1. str:Unicode
      2. bytes:bytes
    • 註意點:Unicode、utf8、gbk都是編碼規則
      為什麽內存存儲Unicode
      程序執行前和執行後兩個狀態

二. 基礎語法回顧

  1. 數據類型
  2. 變量
  3. 縮進
  4. 運算符
    • 算數運算符
    • 賦值運算符
    • 比較運算符
    • 比較運算符
    • 邏輯運算符
    • 關系運算符
    • 位運算符
  5. 數據類型
    • 可變數據類型:列表 字典
    • 不可變數據類型:整形 元組 字符串 一旦創建不能改修改
    • 整型
    • 浮點型:科學計數法
      • float
      • double
    • 布爾類型:true 1;false 0
    • 字符串
      • 轉義符號
      • 查找:切片[:]
      • strip():把字符串開頭和結尾的空格以及\n去掉或者在括號中間增加制定字符
    • NoneType:None
  6. 字符串操作
    • 拼接方法:join
print("*".join(["I","am","world!"])
輸出為 I\*am\*world!
    • 分割方法:split() 按指定符號或空格分割字符串組成列表
      splitlines 以\n為分隔符
    • 查找字符:find() 返回位置
      index()
      index與find的區別:find沒找到回返回-1,index 會報錯
    • 替換字符:replace()
    • center 居中
      ljust 左對齊
      rjust 右對齊
    • 字符串的格式化輸出:format
      %s 字符串占位
      %d 整型
      %f 浮點型 精度要求小數點4幾位 %.4f

print("hello {0}, his age is {1}".format("alex",34))        #必須從0開始
print("hello {name}, his age is {age}".format(name = "alex", age = 34))        #鍵值對
print("hello {name}, his age is {age}".format_map({"name" : "alex", "age" :34}))     #後面跟字典
    • 判斷是否是數字
      isdecimal
      isdigit
      is number 可判斷中文大寫數字、羅馬數字

    • 首字母大寫
      capitalize 句子首字母大寫
      title 句子所有首字母大寫
    • expendtabs
      對tab\t 進行擴展
print("hello\tworld".expendtab())
    • 輸出為間距8
    • 其他
      zfill 左邊補0
  1. 列表操作

作業

今日總結

Python全棧之路Day15