注释

单行注释 # 多行注释 """ """

数据类型

t=type(x)

强制类型转换

a=float(a)

print(a3[-1],a3[2:6]) //不包括最后一位
print(a3[0:-1],a3[:-1],a3[1:])
print(a3[2:7:2]) # low:hight:step

a3.append(10)

a7=list(a6.keys())

int

a1=1

str

a2='123'

list

a3=[1,2,3]

tuple

a4=(1,2,3)

dict

a6={"js":"nj","zj":"hz","ah":"hf"} 

key:val

逻辑运算

and //not &&

or //not ||

2 in a3
'2' in a2

IO

print(x)

print("sum1:{};sum2:{}".format(a1,a2))

score=eval(input("输入成绩:"))

print(a6['zj'],a6.get('zj'))
print(a6.get('jx')) #a6['jx'], //若没有a6,get返回空,#a6['jx']报错

循环&&条件判别

x=range(1,100)#不包括100
print(x)

lx=list(x)
print(lx)

sx="abcdefg"

for i in sx:
print(i)

sum=0
for i in x:
sum+=i;
print(sum)

len(sx)=>8

range(len(sx))=>range(8)=>[0,1,2,3,...]

for i in range(len(sx)):
print(sx[i])

i=0
while i<len(sx):
print(sx[i])
i+=1

score=eval(input("输入成绩:"))
if score==100:
print("满分")
elif score>=90:
print("优秀")
elif score>=80:
print("良好")
elif score>=60:
print("及格")
else :
print("不及格")

Last modification:November 17th, 2020 at 03:09 pm