标签:rom lam 报错 三角形 ret mic 逻辑运算符 缺点 src
import keyword
print(keyword.kwlist)
[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘async‘, ‘await‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘nonlocal‘, ‘not‘, ‘or‘, ‘pass‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]
# 直角三角形
for i in range(6):
print("*"*i)
*
**
***
****
*****
# 等边三角形
for i in range(1,6):
for j in range(1,6-i):
print(" ",end="")
print("* "*i)
*
* *
* * *
* * * *
* * * * *
# 九九乘法表
for i in range(1,10):
for j in range(1,i+1):
print("%d*%d=%2d"%(j,i,j*i),end=‘ ‘)
print("")
1*1= 1
1*2= 2 2*2= 4
1*3= 3 2*3= 6 3*3= 9
1*4= 4 2*4= 8 3*4=12 4*4=16
1*5= 5 2*5=10 3*5=15 4*5=20 5*5=25
1*6= 6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7= 7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8= 8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9= 9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
#通过代码针对str="abcdefg" :
# 1取出bcd
# 2将str倒序
# 3取出bdf
str="abcdefg"
print(str[1:4])
print(str[::-1])
print(str[1::2])
# 通过代码针对str = "hello world python and python"进行如下操作
# 1.找到右边第一个p的索引
# 2.找z结果要求报错
# 3.将所有空格替换成逗点
# 4.通过逗点生成一个列表
# 5.将d全部替换成大写D
str = "hello world python and python"
print(str.rfind(‘p‘))
print(str.find(‘z‘)) # =====>-1
print(str.index(‘z‘)) # =====>报错
print(str.replace(‘ ‘,‘,‘))
print(str.replace(‘ ‘,‘,‘).split(‘,‘))
print(str.replace(‘d‘,‘D‘))
# a = [1,2,3,4,5,6],在a中元素5前添加一个5.5元素
# 在a中元素6后面添加"我心态炸了"
# 删除a中的元素1
a = [1,2,3,4,5,6]
a.insert(4,5.5)
a.append(‘加油‘)
a.remove(1)
print(a)
# b = ["a","b","c","b","a"]
# 查找索引区间在2-4的“b”的索引
# 查找索引区间在3-4的“a”的索引
b = ["a","b","c","b","a"]
print(b.index(‘b‘,2,4))
print(b.index(‘a‘,-1))
标签:rom lam 报错 三角形 ret mic 逻辑运算符 缺点 src
原文地址:https://www.cnblogs.com/fairytalk/p/13160759.html