从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)
相关推荐
闵孚龙1 小时前
动态图机制:为什么 PyTorch 调试起来更舒服
人工智能·pytorch·python
chushiyunen1 小时前
langchain4j笔记、tools
笔记·python·flask
程序员三藏2 小时前
Web自动化测试详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
在放️2 小时前
Python 爬虫 · 第三方代理接入与合规使用
开发语言·爬虫·python
KANGBboy3 小时前
java知识五(继承)
java·开发语言
c++之路3 小时前
Bazel C++ 构建系列文档(三):构建第一个 C++ 项目
开发语言·c++
AI人工智能+电脑小能手3 小时前
【大白话说Java面试题 第117题】【并发篇】第17题:线程有几种状态,之间如何转换?
java·开发语言·面试
财经资讯数据_灵砚智能3 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年6月14日
大数据·人工智能·python·ai·信息可视化·自然语言处理·灵砚智能
聚名网4 小时前
域名net,com,cn有区别吗?有哪些不同呢?
服务器·开发语言·php
牛油果子哥q4 小时前
STL set与map底层精讲,红黑树适配原理、有序去重特性、迭代器遍历、API实战与面试核心考点全解
开发语言·数据结构·c++·面试