python个人总结

个人总结

python

  1. python
  2. 数列
  3. 元祖
  4. 排序

一个数所有位数中的最大值

“”"num=int(input(“输入该数”))
c=0
mx=0

while num>0:
c=num%10
num=num//10
if mx<c:
mx=c
print(mx)"""

统计字符大小写字母,数字的个数,并求出来最大值和最小值

“”“i=1
j=0
p=0
q=0
zf=input(“请输入字符”)
zd=ord(zf)
zx=ord(zf)
while i<=10:
zf=input(“请输入字符”)
if “a”<=zf<=“z”:
j+=1
if “A”<=zf<=“Z”:
p+=1
if “0”<=zf<=“9”:
q+=1
if zd<ord(zf):
zd=ord(zf)
if zx>ord(zf):
zx=ord(zf)
i+=1
print(“总共有”,j,“个小写字母”)
print(“总共有”,p,“个大写字母”)
print(“总共有”,q,“个数字”)
print(“ASCii最大的是”,zd)
print(“ASCii最小的是”,zx)”""

10到20从10开始的数字,跳过7的倍数,到个位数是7的停止

“”"shu=10
while shu<=20:
if shu%7==

  • List item

0:
shu+=1
continue
if shu%10==7:
break
print(shu)
shu+=1"""

对range的运用

#for i in range(5):

print(i)

#for i in range(3,9):

print(i)

#for i in range(2,19,3):

print(i)

#for i in range(18,6,-3):

print(i)

数列的运用

“”“a=[]
b=[1,2]
print(type(a),a)
print(type(b),b)”""

“”“a=[1,“a”,”/"]
print(a[0],a[1],a[2])"""

“”“b=[1,“a”,“A”,”.",“啊”]
x=len(b)
print(“长度”,x)
i=0
while i<len(b):
print(“第”,i+1,“个值是”,b[i])
i+=1"""

“”“a=[1,2]
b=[3,4,5]
c=a+b
d=a*3
f=a[1]+b[2]
print©
print(d)
print(f)”""

“”“a=[”.",“f”,1,“呵呵”]
for x in range (len(a)):
print(a[x])"""

“”“a=[1,2,3,4,5,6,7,8]
b=a[2:5]
print(b)”""

“”“a=[“阿勒”,“咿呀”,“我去”,1,4,“a”,“t”,“f”,5]
b=a[1:7:2]
c=a[3:]
d=a[:4]
f=a[-3:-1]
g=a[-1:-4:-1]
for i in range(-1,len(a)-1,-1):
print(a[i])
print(b)
print©
print(d)
print(f)
print(g)
“””
“”“a,b=[1,2]
print(a,b)”""

“”“a,*b=[1,2,3]
print(a)
print(b)”""

“”“a=[1,2]
a.append(9)
print(a)”""

“”“a=[1,2]
b=[3,4]
a.extend(b)
print(a)”""

“”“a=[3,5,9,7]
a.insert(2,“z”)
print(a)”""

“”“a=[“a”,“c”,“d”,9]
b=a.pop()
print(a,b)”""

“”“a=[1,8,4,3,0,2]
b=a.pop(4)
print(a,b)”""

“”“a=[5,3,0,“w”,“g”,0,5,2]
a.remove(“w”)
print(a)”""

“”“a=[4,2,1,7,4,9,1]
del a[4]
print(a)”""

“”“a=[4,9,“w”,“e”,3,5,7,8]
a[5]=88
print(a)”""

“”“a=[1,6,8,3,2,1,7,54,3]
a.reverse()
print(a)”""

“”“a=[2,9,54,2,4,1,7,45]
a.sort()
print(a)”""

“”“a=[3,6,3,2,6,8,11,5]
b=sorted(a)
print(b)”""

“”“a=[7,4,2,5,1,5,9,11,44,1,0,33]
a.sort(reverse=True)
print(a)”""

python的等号的作用

“”“a=3
b=4
t=a
a=b
b=t
print(a,b)”""

“”“a=[2,3,4,1,2,3,4,9,65,3,5,6,1]
b=a.count(2)
print(b)”""

“”“a=[32,55,32,55,4,2,11,0]
b=a.index(2)
print(b)”""

“”“a=[[13,2,7,3],[3,5,11,83,3],[5,3,8,5,6,2]]
for b in a:
print(b)
for c in b:
print(c,end=”")
print()"""

“”“print(1,end=“w”)
print(2)”""

“”“a=[[1,2,3],[6,3,4,1],[8,4,6,22,5]]
print(a[1][2])”""

“”“a=1
b=a
a=3
print(a,b)”""

“”“a=[1,2,3]
b=a
a.append(4)
print(a)
print(b)”""

“”“a=“abc”
b=“abc”
print(id(a))
print(id(b))”""

“”“a=3
b=3
print(a==b)
print(a is b)”""

“”“a=[1,2,3]
b=[1,2,3]
print(a==b)
print(a is b)
print(id(a))
print(id(b))”""

深拷贝和浅拷贝和等号的区别

“”“import copy
a=[1,2,3,[4,5],6,7]
b=a
c=copy.copy(a)
d=copy.deepcopy(a)
a.append(“w”)
a[3].append(“e”)
print(a,id(a))
print(b,id(b))
print(c,id©)
print(d,id(d))”""

“”“a=(1,2,3)
print(a,type(a))
print(a[0])
#a[0]=9
#print(a)”""

for循环的运用

“”“a=(1,2,3)
for x in a:
print(x)
i=0
while i<len(a):
print(a[i])
i+=1"”"

“”“a=(3,4)
b=(1,2)
c=a+b
d=a*2
print©
print(d)”""

元祖

“”“a,b,c=(1,2,3)
print(a)
print(b,c)”""

“”“a,*b=(1,2,3)
print(a)
print(b)”""

“”“a=(1,2,3,4,[5,6],7)
a[4].append(8)
print(a)”""

“”“a=[1,2,3]
b=tuple(a)
print(b)
c=list(b)
print©”""

“”“a=(“t”,“m”,“c”,“e”,“f”,“g”)
b=a.index(“m”,1,2)
print(b)”""

“”“a=((“张三”,19),(“李四”,20),(“王五”,30))
for x in a:
print(x)”""

“”“a=((“张三”,19),(“李四”,20),(“王五”,30))
for x,y in a:
print(x,y)”""

“”“a=(11,5,2,“p”,“ka”)
for x in enumerate(a):
print(x)”""

“”“a=(3,1,6,8,2,9,2)
he=0
i=0
while i<len(a):
he+=a[i]
i+=1
print(he)”""

“”“a=(1,4,7,2,9,7,3,17,18,21,14,98)
gs=0
for x in a:
if x%70 or x//107:
gs+=1
print(x,“是”)
print(gs)”""

“”“a=(1)
b=(1,)
c=1,
print(type(a),type(b),type©)”""

“”“a=(3,4,8,1,0,3,6,4,8,11,17,87,66)
os=0
js=0
for x in a:
if x%2==0:
os+=1
else:
js+=1
print(os,js)”""

“”“a=(3,4,8,1,0,3,6,4,8,11,17,87,66)
os=0
js=0
i=0
while i<len(a):
if a[i]%2==0:
os+=1
else:
js+=1
i+=1
print(os,js)”""

“”“a=(3,7,1,9,0,11,66,1,16)
mx=a[0]
mn=a[0]
i=0
while i<len(a):
if mx<a[i]:
mx=a[i]
if mn>a[i]:
mn=a[i]
i+=1
c=a.index(mx)
d=a.index(mn)
print(mx,c)
print(mn,d)”""

“”“a=(3,7,1,9,0,11,66,1,16)
mx=a[0]
mn=a[0]
for x in a:
if mx<x:
mx=x
if mn>x:
mn=x
c = a.index(mx)
d = a.index(mn)
print(mx, c)
print(mn, d)”""

“”“a=[1,2,3,3,2,5]
b=[11,22,8,7,5,9]
c=[]
i=0
while i<len(a):
b[i]+=a[i]
i+=1
c=b
print©”""

“”“a=[1,2,3,3,2,5]
b=[11,22,8,7,5,9]
c=[]
i=0
while i<len(a):
d=a[i]+b[i]
c.append(d)
i+=1
print©”""

“”“a=[11,12,13,14,15,16]
t=a[0]
i=0
while i<len(a)-1:
a[i]=a[i+1]
i+=1
a[i]=t
print(a)”""

“”“import time
a=[11,12,13,14,15,16]
while True:
t = a[0]
i = 0
while i < len(a) - 1:
a[i] = a[i + 1]
i += 1
a[i] = t
print(a)
time.sleep(1)”""

“”“a=[1,2,3,4,5,6]
i=0
while i<len(a)//2:
t=a[i]
a[i]=a[len(a)-i-1]
a[len(a)-i-1]=t
i+=1
print(a)”""

“”“a=[1,2,3,4,5,6]
i=0
j=len(a)-1
while i<j:
t=a[i]
a[i]=a[j]
a[j]=t
i+=1
j-=1
print(a)”""

“”“a=4
b=3
a,b=b,a
print(a,b)”""

“”"a=[1,2,3,4,5,6]
i=0
while i<len(a)//2:
a[i],a[len(a)-i-1]=a[len(a)-i-1],a[i]

i+=1

print(a)"""

“”“a=[1,2,3,4,5,6]
i=0
j=len(a)-1
while i<j:
a[i],a[j]=a[j],a[i]
i+=1
j-=1
print(a)”""

“”“a=[1,2,3,4,1,2,5,1,1,2]
b=[1,2]
i=0
g=0
while i<len(a):
if a[i]==b[0] and a[i+1]==b[1]:
g+=1
i+=1
print(g)”""

上一篇:BZOJ 2457[BeiJing2011] 双端队列(找规律)


下一篇:HDU - 5411 CRB and Puzzle 矩阵快速幂