从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)
相关推荐
云程笔记16 分钟前
004.环境搭建基础篇:Python、CUDA、cuDNN、PyTorch/TensorFlow安装与版本兼容性踩坑
pytorch·python·tensorflow
小成202303202655 小时前
Linux高级02
linux·开发语言
知行合一。。。6 小时前
Python--04--数据容器(总结)
开发语言·python
架构师老Y6 小时前
008、容器化部署:Docker与Python应用打包
python·容器·架构
咸鱼2.06 小时前
【java入门到放弃】需要背诵
java·开发语言
ZK_H6 小时前
嵌入式c语言——关键字其6
c语言·开发语言·计算机网络·面试·职场和发展
A.A呐6 小时前
【C++第二十九章】IO流
开发语言·c++
椰猫子6 小时前
Java:异常(exception)
java·开发语言
lifewange6 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
pluvium276 小时前
记对 xonsh shell 的使用, 脚本编写, 迁移及调优
linux·python·shell·xonsh