1. 程式人生 > 實用技巧 >python基礎--(三)轉義序列

python基礎--(三)轉義序列

\ 反斜槓
' 單引號
" 雙引號
\a ASCII響鈴
\b ASCII退格
\f ASCII進紙 (翻頁功能)
\n ASCII換行
\N{name} Unicode資料庫中的字元名,其中name是它的名字,僅Unicode使用
\r ASCII回車 原地重新整理(行)
\t ASCII水平製表
\uxxxx 值為16位十六進位制xxxx的字元
\uxxxx 值為32位十六進位制xxxxxxxx的字元
\v ASCII垂直製表
\ooo 值為八進位制值ooo的字元
\xhh 值為十六進位制hh的字元

1 print('How old are you?',end = ' ')
2 age = input()
3 print('how tall are you ',end = ' ')
4 height = input()
5 print('how much du you weight ',end = ' ')
6 weight = input()
7 line = 'So,you are {}old,{} tall and {} heavy.'
8 print(line.format(age,height,weight))
x = int(intput()):表示將輸入的數字字元轉換成 int型別
也可以提示:
input("How old are you? ") #帶提示的輸入

  pychod #python 的說明文件
  例如:pychod input
  
  from sys import argv      #從外部命令列輸入引數  類似  int main(int agv ,char **agc)
  py_name , canshu1 = argv       #必須要相同數量引數

  讀取檔案:
        txt = open(檔名)        #txt儲存的是一個叫檔案物件的東西
        print(txt.read())      #直接輸出檔案內容

  讀寫檔案:
        close:      關閉檔案
        read:       讀取檔案的內容
        readline:      只讀取文字檔案中的一行
        truncate:      清空檔案      fileObject.truncate( [ size ])      #截斷檔案 將size位元組刪除
        write('stuff'):      將'stuff'寫入檔案中
        seek(0):            將讀寫位置移動到檔案開頭
   'r'       open for reading (default)      'r'開啟讀取(預設)
   'w'       open for writing, truncating the file first      'w'開啟寫入,先截斷檔案
   'x'       create a new file and open it for writing      'x'建立一個新檔案,並開啟它進行寫入
   'a'       open for writing, appending to the end of the file if it exists      “a”開啟以寫入,如果存在,則附加到檔案的末尾
   'b'       binary mode      “b”二元模式
   't'       text mode (default)      't'文字模式(預設)
   '+'       open a disk file for updating (reading and writing)      '+'開啟磁碟檔案進行更新(讀和寫)
  
  更多檔案操作
        from os.path import exists
        exists(檔名)      #檢測檔案是否存在      存在返回true 否則返回 false
        len()            #返回字串的長度