Python相關基礎
1》變量:
2》條件判斷與縮進:
sex = raw_input("Please input your gender:")
if sex == "girl":
print ("I would like to have a little monker with jj!")
elif sex == "man":
print ("Going to homosexual!")
else:
print
=====================
lunkey_number = 8
number = input("Please input your guess number:")
if number > lunkey_number:
print ("Your guess number is too big,please input again:")
elif number < lunkey_number:
else:
print ("Your guess number is correct,you are lunkey!")
3》循環控制
優化代碼:
4》常用數據類型:
數字:
Int
Float
Long
布爾:
真或假
1或0
字符串:
1>字符串的格式化:
2>字符串常用功能:
移除空白:可以去掉兩邊空格,也可去掉兩邊字符;
分割:
長度:
索引:
切片:
1>固定頭部,不固定尾部,包含頭部,不包含尾部;
2>指定分割的距離,不包含指定所用的索引
replace():轉換特定字符;可以指定位置,將前幾個替換;
splitlines():按照換行符來分割;
swapcase():大小寫轉換;
列表:可以存多個信息
append:追加
eg:name_list.append("haha")
count:計算,統計;計算其中某個元素有幾個
eg:name_list.count("haha")
extend:擴展
index:索引,輸出最近的一個,如果有相同的
eg:name_list.index("che")
insert:插入,在某個位置插入一個元素
eg:name_list.insert(2,"hhehe")
pop:刪除一個,每次都刪除最後一個;
eg:name_list.pop()
remove:刪除指定的一個
eg:name_list.remove("zhang")
reverse:反轉,元素排序相反;
sort:排序,安裝ASSCI碼排序,數字排在最前面;
eg:a.sort()
extend():擴展列表;
元組:
tuple():可以將列表轉換為元組;
count():查看某元素出現的次數;
字典 :
fromkeys():生成一個新字典;
get():當key不存在時可以輸出一個默認值;
keys(),values(),items():
pop():刪除某個鍵對,需要制定key值;
update():更新字典;
Python相關基礎