1、如何拼接两个列表?
class_1
= ["张三", "李四"]
class_2
= ["王五", "钱六"]
class_1
= class_1
+ class_2
class_1
.extend
(class_2
)
2、如何判断列表为空?
while True:
out_student
= class_1
.pop
()
print(f
"{out_student}-离开了教室")
if len(class_1
) == 0:
print("学生都离开了!")
if not class_1
:
break
3、如何反转字符串?
word
= "Hello World!!!"
word_list
= list(word
)
word_list
.reverse
()
print("".join
(word_list
))
print(word
[::-1])
4、如何用Python实现LeetCode:旋转数组?
array
= [-1, 2, 7, -9, 10]
def rotate(nums
, k
):
i
= k
% len(nums
)
nums
[:] = nums
[-i
:] + nums
[:-i
]
print(nums
)
rotate
(array
, 11)
转载请注明原文地址:https://tech.qufami.com/read-1054.html