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练习题(基础知识练习题)的主要内容,如果未能解决你的问题,请参考以下文章

240个Python练习案例附源码(百看不如一练)

实例三十九 序列插入排序 python编程天天练

Python练习之基础语法数据类型字符编码文件操作

PTA|Python浙大版《Python 程序设计》题目集:第四章(适合Pythno新手的基础练习题集)

python基础练习之购物车小程序

python练习之银行模拟系统