千家信息网

python序列的基本操作有哪些

发表于:2025-02-09 作者:千家信息网编辑
千家信息网最后更新 2025年02月09日,这篇文章给大家分享的是有关python序列的基本操作有哪些的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。创建序列语法:变量名 ={}dict={}变量名 =[]list01
千家信息网最后更新 2025年02月09日python序列的基本操作有哪些

这篇文章给大家分享的是有关python序列的基本操作有哪些的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

创建序列语法:

变量名 ={}

dict={}

变量名 =[]

list01=[]

变量名 =() 不可变

tuple01=()

变量名 =值

str='123'

备注:序列中除了元祖之外都可以有增删改查的功能

#增加 字典
stu_info={'num':'001','name':'袁天罡','sex':'男'}
stu_info['age']='78'
print(stu_info)

#列表
list01=['002','李淳风','男']
list01.append(64)
print(list01)

#字符串
str01='003\t武则天\t女'
str01='003\t武则天\t女\t59'
print(str01)

#删除
#字典
stu_info={'num':'001','name':'袁天罡','sex':'男'}
del stu_info['sex']
print(stu_info)

#列表
list01=['002','李淳风','男']
del list01[2]
print(list01)

#字符串

str01='003\t武则天\t女'

str01='003\t武则天'
print(str01)

#改

#字典
stu_info={'num':'001','name':'袁天罡','sex':'男'}
stu_info.update({'sex':'女'})
print(stu_info)

#列表
list01=['002','李淳风','男']
list01[2]='不详'
print(list01)

#字符串
str01='003\t武则天\t女'
str01='003\t武则天\t男'
print(str01)

综合案例演示:制作学生信息管理系统

nameinfo=[]

def printMemu():
print("="20)
print("==学生管理系统V1.0==")
print("="
20)
print("1:添加学生信息")
print("2:删除学生信息")
print("3:显示学生信息")
print("4:退出系统")

def add():
num=input("请输入学生学号:")
nmae=input("请输入学生姓名:")
sex=input("请输入学生性别(男/女)")
newInfo={}
newInfo['num']=num
newInfo['name']=nmae
newInfo['sex']=sex
nameinfo.append(newInfo)
print(nameinfo)

def show():
print("="20)
print("学生信息如下:")
print("="
20)
print(nameinfo)

def delete():
del_num=input("请输入要删除的学生学号:")
for i in nameinfo:
if i['num']==del_num:
nameinfo.remove(i)

while True:
printMemu()
chose=int(input("请输入功能相对应的数字"))
if(chose==1):
print("1:添加学生信息")
add()

if(chose==2):    print("2:删除学生信息")            delete()if(chose==3):    print("3:显示学生信息")    show()if(chose==4):    print("4:退出系统")    break

感谢各位的阅读!关于"python序列的基本操作有哪些"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

0