如何访问元组中的特定元素?

时间:2017-03-05 07:28:59

标签: python-2.7 tuples

tupMonNames = [" 1月"," 2月"," 3月"," 4月"," 5月" " 6月"" 7月"" 8月"" 9月"" 10月""十一月"" Decmber"]

如何显示以' J'开头的元素?使用循环?

1 个答案:

答案 0 :(得分:1)

对字符串使用 startswith 内置函数。

for item in tupMonNames:
    if item.startswith('J'):
            print item

结果:

January
June
July
相关问题