1. 已知一个字符串为 “hello_world_yoyo”,如何得到一个队列 [“hello”,”world”,”yoyo”] ?
a = "hello_world_yoyo"
print(a.split("_"))
# 2. 有个列表 [“hello”, “world”, “yoyo”],如何把列表里面的字符串联起来,得到字符串 “hello_world_yoyo”?
a=["hello", "world", "yoyo"]
print("_".join(a))
# 3. 把字符串 s 中的每个空格替换成”%20”,输入:s = “We are happy.”,输出:“We%20are%20happy.”。
s = "We are happy."
print(s.replace(" ","%20"))
# 4.统计字符串“Hello, welcome to my world.” 中字母 w 出现的次数
letter = "hello, welcome to my world"
print(letter.count("w"))
# 5.判断字符串 a = “welcome to my world” 是否包含单词 b = “world”,包含返回 True,不包含返回 False。(用函数解答)
a= "welcome to my world"
b= "world"
list_a = a.split(" ")
if b in list_a:
print("Ture")
else:
print("False")
# 6.求 1+2+3…+100 相加的和
def sum(s):
result = 0
for item in range(1,s+1):
result+=item
pass
return result
print(sum(100))