Python基础与进阶:从基础语法到函数应用
1. 基础Python知识
1.1 列表测试
在Python中,我们可以对列表进行各种操作和测试。例如:
print("y_list contains {} objects".format(len(y_list)))
print("big_list contains {} objects".format(len(concat_list)))
# Test your lists
if x_list.count(x) == 10 and y_list.count(y) == 10:
print("Almost there...")
if concat_list.count(x) == 10 and concat_list.count(y) == 10:
print("Great!")
上述代码可以用来测试列表中元素的数量是否符合预期。
1.2 字符串操作符
字符串操作符能让我们对字符串进行丰富的操作:
- 字符串拼接 :使用 + 进行算术拼接。
helloworld = "Hello," + " " + "World!"
print(helloworld)
- 字符串重复 :使用
*可以让字符串重复多次。
超级会员免费看
订阅专栏 解锁全文
815

被折叠的 条评论
为什么被折叠?



