从小白开始,洞察Python之妙
接触Python一段时间了,来这里总结一下Python的基础。希望给各位初学者提供复习帮助。
——初学者的回忆录
Python基础知识思维导图:
回顾学习进程:
1.输入超过五位数的整数,输出数字+万
(初识Python)
X = int(input("请输入一个超过五位数的整数")) #将输入的X转换为整数类型
X_A = int( X / 10000 ) #将输入的X除以10000
X_K = int( X / 1000 ) #将输入的X除以1000
print(X_A,"万") #赋予单位万
print(X_K,"K") #赋予单位K
考察:Python输入输出,字符串的类型转换,变量命名。
2.计算学分绩点
(小试身手)
score = 0
credit = 0
suject_number = 0
GPA = 0
Average_GPA = 0
a = 0
while True:
score =input("请输入该课程的分数:")
credit = int(input("请输入该课程的学分:"))
if score == "stop":
break
if score == "优秀":
GPA =4.5
suject_number = suject_number + 1
a = GPA*credit
print(GPA)
if score == "良好":
GPA =3.5
suject_number = suject_number + 1
a = a+GPA*credit
print(GPA)
if score == "中等":
GPA =2.5
suject_number = suject_number +1
a = a+GPA*credit
print(GPA)
if score == "及格":
GPA =1.5
suject_number =suject_number +1
a = a+GPA*credit
print(GPA)
if score == "不及格":
GPA = 0
suject_number =suject_number +1
a = a+GPA*credit
print(GPA)
print(a/suject_number)
考察:【流程控制语句】判断语句与循环语句的使用。
3.打印九九乘法表
(举一反三)
for i in range(1,10):
for x in range(1,10):
print(str(i)+"*"+str(x)+"="+str(i*x),end=" ")
4.寻找2017年1月到3月的周一/二/…/日
(再接再厉)
a=[]
b=[]
for x in range(20170101,20170132): #在for in 遍历中用内置函数range创建列表
a.append(x) #将列表放入a中
for y in range(20170201,20170229):
a.append(y) #同上
for z in range(20170301,20170332):
a.append(z) #同上
b=a[ : :6] #用步数做成切片
print(b)
考察:【流程控制语句】for循环;【组合数据类型】列表的使用。
5.输入数字,输出对应的星期数
(学而不厌)
w="星期一 星期二 星期三 星期四 星期五 星期六 星期天"
f=w.split(" ")
a=eval(input('请输入表示星期的而数字:'))
print(f[a-1])
考察:字符串操作;【组合数据类型】列表操作。
6.字符串练习
(训练日常)
s = 'abcABCabc'
s.lower() #小写
s.upper() #大写
输出:‘abcabcabc’ ; ‘ABCABCABC’
a = 'a b c 123,456'
a.split(" ") #分隔
输出:[‘a’, ‘b’, ‘c’, ‘123,456’]
v = '1234556'
v.count('5') #计数
输出: 2
f = '$$50%%'
f.strip('$%') #删除
输出:‘50’
j = 'abcde'
'@'.join(j) #增加
输出:‘a@b@c@d@e’
7.算法练习
(训练日常)
isinstance(12j, float) + 12 #isinstance判断,返回布尔值
输出:12
int('22', 16) #22的16进制
输出:34
int(abs(4-3j)) #4-3j 的绝对值(模)
输出:5
int( 50 ** .5 ) #50开根,输出整数部分
输出:7
(not 3) + 5 #not 3 输出布尔值0
输出:0