Python學習記錄-2016-12-17

來源:互聯網
上載者:User

標籤:學習記錄

今日學習記錄

模組:

import os#匯入os模組import sys#匯入sys模組os.system("df -h")#執行df -h命令cmd_res = os.popen("df -h").read()#將命令的返回結果賦值給cmd_res,如果不加入.read()會顯示命令的返回加過在記憶體的位置print(sys.path)#顯示系統變數路徑,一般個人模組位於site-packages下,系統模組位於lib下print(sys.argu[2])#執行時候python xxx.py 1 2 3,列印結果顯示3,從0開始計算。

資料類型

str字串

float浮點數,一般理解為小數,但是小數有很小的區別;

數字,沒有python2中的long概念,統一為int;

常量一般為大寫;

byte類型:二進位儲存,一般儲存電影;

轉換:

str轉換為byte

msg = "我愛北京天安門"print(msg.encode())#預設為utf-8

byte轉換為str

msg = "我愛北京天安門"print(msg.encode().decode)#預設為utf-8

三元運算:

a,b,c = 1,3,5d=a if a<b else c#得到d=1d=a if a>b else c#得到d=5

運算子號

+ - * /

幾次方**

// 得到除法結果的整數

%得到除法結果的餘數

==等於

!=不等於

<>不等於

<=小於等於

>=大於等於

<小於

>大於

and和

or或

in屬於

not in不屬於

list列表操作

names = ["zhangsan", "lisi", "wangwu", "", "zhaoliu"]print(names)print(names[0])print(names[0:3])print(names[1:3])print(names[:3])print(names[-3:-1])print(names[-3:])names.insert(1,"sunqi")names.append("zhaoba")del names[2]names.remove("wangwu")names[2] = "zhoujiu"names.index("wangwu")names.count("wangwu")name2 = [1,2,3,4]names.extend(names2)names.reverse()names.sort()import copynames3 = names.copy()#此copy不copy list記憶體在的listnames3 = copy.deepcopy(names)for i in names:    print(i)


Python學習記錄-2016-12-17

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.