从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)
相关推荐
卷无止境11 小时前
FastAPI的测试事件在测什么?
后端·python·fastapi
selfsongs11 小时前
Python学习之——multiprocessing 多进程编程
python
平常心的技术小牛11 小时前
Qt-快速上手-QLabel
开发语言·qt
卷无止境11 小时前
FastAPI CLI 你需要认识这把命令行利器
后端·python·fastapi
XR12345678811 小时前
工厂办公楼无线网络:多楼层覆盖与访客体验怎么选?
开发语言·php
JL1511 小时前
Java并发编程面试全攻略-从synchronized到AQS底层原理
java·开发语言·面试·并发编程
云泽80811 小时前
Python 开发环境搭建全指南:从 Python 安装到 PyCharm 配置详解
开发语言·python·pycharm
IT小白杨11 小时前
海外业务账号安全保障:主流浏览器产品底层机制对比
数据库·python·安全·自动化·安全架构·指纹浏览器
不会代码的小猴11 小时前
2. 了解Qt
开发语言·c++·笔记·qt·算法
ZC跨境爬虫11 小时前
LeetCode 119. 杨辉三角 II(原地更新优化详解 + Java Python 实现)
java·python·leetcode