Python练习题(基础知识练习题)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python练习题(基础知识练习题)相关的知识,希望对你有一定的参考价值。
1、请用代码实现:利用下划线将列表的每一个元素拼接成字符串,li = [‘alex‘,‘eric‘,‘rain‘]
#!/usr/bin/env python
# -*- coding:utf-8 -*-
li = [‘alex‘,‘eric‘,‘rain‘]
v = ‘_‘.join(li)
print(v)
2、查找列表中元素,移除每个元素的空格,并查找以 a 或 A 开头 并且以 c 结尾的所有元素。
li = ["alec", " aric", "Alex", "Tony", "rain"]
tu = ("alec", " aric", "Alex", "Tony", "rain")
dic = {‘k1‘: "alex", ‘k2‘: ‘ aric‘,"k3": "Alex", "k4": "Tony"}
#!/usr/bin/env python
# -*- coding:utf-8 -*-
li = ["alec", " aric", "Alex", "Tony", "rain"]
for S in li:
S = S.strip()
prefix_a = S.startswith(‘a‘)
prefix_A = S.startswith(‘A‘)
suffix_c = S.endswith(‘c‘)
if prefix_a or prefix_A and suffix_c:
print(‘要查找的元素:%s‘ % S)
tu = ("alec", " aric", "Alex", "Tony", "rain")
for S in tu:
S = S.strip()
prefix_a = S.startswith(‘a‘)
prefix_A = S.startswith(‘A‘)
suffix_c = S.endswith(‘c‘)
if prefix_a or prefix_A and suffix_c:
print(‘要查找的元素:%s‘ % S)
dic = {‘k1‘: "alex", ‘k2‘: ‘ aric‘,"k3": "Alex", "k4": "Tony"}
for S in dic.values():
S = S.strip()
prefix_a = S.startswith(‘a‘)
prefix_A = S.startswith(‘A‘)
suffix_c = S.endswith(‘c‘)
if prefix_a or prefix_A and suffix_c:
print(‘要查找的元素:%s‘ % S)
http://www.cnblogs.com/lianzibing/p/6105287.html
以上是关于Python练习题(基础知识练习题)的主要内容,如果未能解决你的问题,请参考以下文章