从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)
相关推荐
MegaDataFlowers5 小时前
依赖注入(DI)
java·开发语言
csbysj20205 小时前
Foundation 输入框尺寸指南
开发语言
wertyuytrewm5 小时前
用Python实现自动化的Web测试(Selenium)
jvm·数据库·python
码云数智-园园5 小时前
Tailwind CSS vs. 传统CSS/Sass:2026年前端样式开发的深度博弈
开发语言
lly2024065 小时前
《jEasyUI 创建 XP 风格左侧面板》
开发语言
晓纪同学5 小时前
EffctiveC++_01第一章
java·开发语言·c++
我真会写代码5 小时前
Java事务核心原理与实战避坑指南
java·开发语言·数据库
2401_846341655 小时前
C++动态链接库开发
开发语言·c++·算法
柠檬Leade5 小时前
IDEA中 java: 程序包lombok不存在 问题解决
java·开发语言·maven·intellij-idea·依赖不存在
小杍随笔6 小时前
【Rust 语言编程知识与应用:闭包详解】
开发语言·后端·rust