text = "Hello, how are you?"
result = text.split(",")# 使用逗号作为分隔符进行分割
print(result)——————['Hello', ' how are you?']
text = "I love apples and oranges and bananas"
result = text.rsplit("and", 2)# 使用"and"作为分隔符进行分割,最多分割两次
print(result)——['I love apples ', ' oranges ', ' bananas']
text = "I have a cat"
result = text.partition("have")
print(result)——('I ', 'have', ' a cat')
text = "I have a cat"
result = text.rpartition("a")
print(result)——('I have ', 'a', ' cat')
('I have a c', 'a', 't') 前面描述的 嵌套字典 中关键字排序:
for id, person in sorted(people.items(), key=lambda x: x['age']):
print....
x 就是外部字典 中的每个字典;
x 就是里面字典;
x['age']: 人员信息的 具体一个值; 阐述以下方法:
@classmethod
@staticmethod
@property
画出三角形ABC,边长分别是 a,b,c
import turtle
# 设置顶点坐标和边长
A = (-100, 0)
B = (100, 0)
C = (0, 150)
a = 200
b = 150
c = 130
# 移动到点A
turtle.penup()
turtle.goto(A)
turtle.pendown()
# 显示顶点A
turtle.write("A", align="right")
# 画出三角形
turtle.goto(B)
turtle.write("B", align="left")
turtle.goto(C)
turtle.write("C", align="center")
turtle.goto(A)
'''
# 显示边长
turtle.penup()
turtle.goto((A+B)/2, (A+B)/2)
turtle.write("a", align="right")
turtle.goto((B+C)/2, (B+C)/2)
turtle.write("b", align="right")
turtle.goto((A+C)/2, (A+C)/2)
turtle.write("c", align="right")
# 隐藏海龟
turtle.hideturtle()
turtle.done()
'''
页:
1
[2]