花了2萬(wàn)多買(mǎi)的Python教程全套,現(xiàn)在分享給大家,入門(mén)到精通(Pytho...


fp=open("D:/text.txt",'a+')
print('helloworld',file=fp)
fp.close()
print("1,"2","3")

print('hello\nworld')
print('hello\tworld')
print('hello\rworld')
print('hello\bworld')
print('老師說(shuō):\‘大家好\’')
print(r'老師說(shuō):\‘大家好\\’')
二進(jìn)制和字符編碼不是特別理解
保留字不能用于給變量命名,區(qū)分大小寫(xiě)
name='瑪利亞'
print('標(biāo)識(shí)',id(name))
print('類(lèi)型',type(name))
print('值',name)
多次賦值后會(huì)指向新空間,也可以多次print


print('十進(jìn)制',118)
print('二進(jìn)制',ob10101111)
print('八進(jìn)制',0o176)
print('十六進(jìn)制',0x1EAF)

n1=2.2
n2=1.1
m3=1.0
print(n1+n2)
解決方案:
from decimal import Decimal
print(Decimal('1.1')+Decimal('2.2'))



數(shù)據(jù)類(lèi)型轉(zhuǎn)換
name='張三'
age=20
print('我叫'+name+'今年'+str(age)+'歲')
注意:
str轉(zhuǎn)換呈int float的前提是引號(hào)里面是整數(shù) 小數(shù)
ture 1;fault 0
float int之間的轉(zhuǎn)換
注釋

input的高級(jí)應(yīng)用 int+input

以下是醫(yī)院筆記
range 三個(gè)參數(shù)
while 四步:
初始變量,條件判斷,條件執(zhí)行體,改變變量
while練習(xí)題:
if a%2 (缺了==2)不執(zhí)行,本求偶數(shù)和結(jié)果卻為奇數(shù)和
改正:if not bool (a%2)
for in操作:
for _in range(5) 以下的print循環(huán)五次
解決同一問(wèn)題,100內(nèi)偶數(shù)和
練習(xí):表示任意一個(gè)數(shù)的個(gè)十百分位數(shù) ,如(100,1000)
個(gè)位 item%10
十位 item//10%10
百位 item//100
循環(huán)方法:
1.for item in range(5)
2.a=1 while<=3時(shí) 加if else 且else后面改變變量:a+=1
continue 不滿(mǎn)足條件就重新執(zhí)行,(0,101)所有不是5的倍數(shù)的數(shù)
else 不遇break就自動(dòng)執(zhí)行
其余有電腦時(shí)候跟練
p29~44完結(jié)
列表 lst=[“ ”,數(shù)字]
index 0~ _ ;–1,–2~_
切片操作 print(lst[start,stop,步長(zhǎng)]);巧用負(fù)數(shù)
判斷(元素是否在列表)和遍歷操作
添加 list.append(元素 );extend;insert(索引,插入內(nèi)容);切片 list[1:]=list3(這里不大理解)
刪除 remove(重復(fù)的就取第一個(gè))
pop(不指定就刪最后一個(gè)) ;
del list;
newlist=list[1,3],list[1,3]=[ ]
修改 list[1,3]=[ ]
排序
list.sort( ) list.sort( reverse ture)
new_list=sorted(list)
desc_list=sorted(list,reverse true) 調(diào)序排序?
字典
無(wú)序,里面是鍵值對(duì),存儲(chǔ)位置和查找通過(guò)哈希函數(shù)計(jì)算,和列表一樣可增刪
創(chuàng)建:{ }or dict()
獲取:scores[ ]orscores.get( )返回none與默認(rèn)值
增刪改 score={ }
del score[ 鍵 ]
score[鍵]=值 (增加和修改)
獲取視圖:
keys=score.keys( )
print(keys); keys,values,items
遍歷 (鍵,值,值)
for item in score
print(item,score.[item],score.get(item))
字典特點(diǎn):...
字典生成式
items=[ ]
prices=[ ]
d={item:price for item, price in zip
( items, prices)}
元組 與字符串一樣是不可變序列,列表和字典是可變序列
生成:
t=( )或者去括號(hào)
t=tuple(( ))
t=(10,) 不加逗號(hào)就是其他類(lèi)型
字典中的元素不能改變,但是其中的可變對(duì)象如列表里面的元素可以改變,改變后id相同
集合 其中元素不可重復(fù)
創(chuàng)建
t=(鍵,鍵,鍵)
print(t)
print(set([ ]))
print(set({ }))
print(set(( )))
print(set(“ ”)) 引號(hào)內(nèi)字母會(huì)分拆開(kāi)?
print(set( )) 直接t={ }是字典類(lèi)型
相關(guān)操作 對(duì)于集合s
增 s.add( )
s.update( )可添加多個(gè),元組字典列表
刪除 s. remove( )
s. discard( )
s. pop()不能指定,從左到右一次刪
集合間的關(guān)系
print s1==s2 s1!=s2
print s1. issubset(s2)
print s1. issuperset(s2)
print s1.isdisjoint (s2) 注意是是否沒(méi)有交集
集合的數(shù)學(xué)操作
交集 print( s1. intersection(s2))
print( s1 & s2)
并集 print( s1. union(s2))
print(s1 | s2)
差集 print( s1. difference(s2))
print(s1 –s2)
對(duì)稱(chēng)差集
print(s1. symmetric_difference(s2))
print(s1 ^ s2)
四種總結(jié),之后在看
字符串!!!
駐留機(jī)制 聽(tīng)不大懂,后面再看



字符串常用操作
大小寫(xiě)轉(zhuǎn)換
s=“ ”
a=s.upper()
lower, swapcase, capotalize, title
注意:改后id不同
對(duì)齊方式
print(s. center(寬度,填充物))
l lift r right zfill(右對(duì)齊)
寬度過(guò)小返回原字符
劈分操作
split rsplit sep maxsplit
print(s. split(sep=“劈分的字符”默認(rèn)是空格,maxsplit=劈分次數(shù)))
判斷操作
