字符串列表 练习题

 

li = ['name', 'age', 'sex']
sn = ''.join(li)  # 列表中的字符串元素串联成新字符串
print(sn)

li = [1, 2, 3, 4, 5]
str_li = [str(el) for el in li]  # 列表推倒式
print(str_li)

s = "apple"
print("_".join(s))



li = ['apple', 'mango', 'banana']
s1 = '*'
print(s1.join(li))



lst = []
s3 = 'alexwusirrain'
lst.append(s3[0])
lst.append(s3[1:])

print(lst)
s = input("输入>>>")
# 解法一
count = 0
for e in s:
    if e.isdigit() and s.index(e) % 2 == 1:
        count += 1
print(count)


# 解法二
count = 0
for i in range(len(s)):
    if s[i].isdigit() and i % 2 == 1:
        count += 1
print(count)

 

posted @ 2020-05-04 18:04  CherryYang  阅读(128)  评论(0)    收藏  举报