从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 分钟前
麒麟 V10 编译 Python 3.11 依赖包缺失与版本冲突问题解决实录
运维·python·麒麟操作系统
多加点辣也没关系2 分钟前
JavaScript|第6章:流程控制语句
开发语言·前端·javascript
Csvn16 分钟前
Python 开发技巧 · 类型注解进阶 —— 从 `TypeVar` 到 `Protocol`,让类型检查真正帮你抓 bug
后端·python
foundbug99922 分钟前
Polar Code 编解码 MATLAB 实现
开发语言·算法·matlab
李小小钦29 分钟前
D. Storming Arasaka(Codeforces 2238)
c语言·开发语言·数据结构·c++·算法
W是笔名30 分钟前
python___容器类型的数据___列表
开发语言·windows·python
跨境数据猎手31 分钟前
多平台电商比价系统从零搭建合规
开发语言·爬虫·架构
花 满 楼33 分钟前
EB引脚配置自动化方案|告别手动繁琐配PIN,Excel+Python批量生成ARXML实现一键配置
python·excel·eb
江华森35 分钟前
jieba 分词 + 共现矩阵构建——《釜山行》人物关系提取(二)
python
用户2986985301441 分钟前
Python 实现 Excel 新旧格式互转:告别 Office 依赖的自动化方案
后端·python·excel