从0开始学python:简单的练习题4

python 复制代码
studentage=[21,25,21,23,22,20]
studentage.append(31)
studentage.extend([29,33,30])
num1=studentage[0]
print(num1)
num2=studentage[-1]
print(num2)
find=studentage.index(31)
print(find)

while循环代码

python 复制代码
list1=[1,2,3,4,5,6,7,8,9,10]
list2=[]
x=0
while x <len(list1):
    if list1[x]%2==0:
        list2.append(list1[x])
    x+=1
print(list2)

for循环代码

python 复制代码
list1=[1,2,3,4,5,6,7,8,9,10]
list2=[]
for x in list1:
    if x%2==0:
        list2.append(x)
print(list2)
python 复制代码
char="万过薪月,员序程马黑来,nohtyp学"
"""
取出字符串倒序
"""
char1=char[::-1]
char2=char1[9:14]
print(char2)
"""
split分割,再replace,再倒叙
"""
char3=char.split(",")
char3=char3[1]
char3=str(char3)
char3=char3.replace("来","")
char3=char3[::-1]
print(char3)
python 复制代码
my_list=['黑马程序员','传播智客','黑马程序员','传播智客','itheima','itcast','itheima','itcast','best']
emptylist=set()
x=0
while x<len((my_list)):
    emptylist.add(my_list[x])
    x+=1
print(emptylist)
相关推荐
Thneonl2 小时前
Celery 生产踩坑:1000 任务积压与 acks_late 双重执行
后端·python
清桔2 小时前
模型的调用
python
小小张说故事2 小时前
Python 多线程为什么跑不快?asyncio 入门指南:异步并发从零上手
后端·python
10年前端老司机2 小时前
干货分享|企业智能知识库 Rerank 重排序落地实践与踩坑总结
python·aigc·agent
天天被压力2 小时前
【Python 量化取数指南 #13】Python 把行情落库:sqlite 一键存,回测随用随取
java·人工智能·python
天天被压力2 小时前
【Python 量化取数指南 #14】Python 清洗行情数据:复权停牌对齐,回测不翻车
java·人工智能·python
Python私教2 小时前
Python环境配置:conda+PyCharm+换源,附6个坑
人工智能·python·pycharm
databook2 小时前
检测数据异常值的五种统计技术
python·数据挖掘·数据分析
小小张说故事2 小时前
Selenium 装驱动太麻烦?Playwright 入门指南:Python 网页自动化新标准
python
海宇数科2 小时前
Python数据工程:利用海宇车型识别精准优化车险理赔合规体验
人工智能·python