Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic operations of python sequences

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you about the basic operation of python sequence. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Create sequence syntax:

Variable name = {}

Dict= {}

Variable name = []

List01= []

Variable name = () immutable

Tuple01= ()

Variable name = value

Str='123'

Note: except Yuanzu, all the sequences can have the function of adding, deleting, modifying and searching.

# add dictionaries

Stu_info= {'num':'001','name':' Yuan Tiangang', 'sex':' male'}

Stu_info ['age'] =' 78'

Print (stu_info)

# list

List01= ['002' Li Chunfeng', 'male']

List01.append (64)

Print (list01)

# string

Str01='003\ t Wu Zetian\ t female'

Str01='003\ t Wu Zetian\ t female\ t59'

Print (str01)

# Delete

# Dictionary

Stu_info= {'num':'001','name':' Yuan Tiangang', 'sex':' male'}

Del stu_info ['sex']

Print (stu_info)

# list

List01= ['002' Li Chunfeng', 'male']

Del list01 [2]

Print (list01)

# string

Str01='003\ t Wu Zetian\ t female'

Str01='003\ t Wu Zetian'

Print (str01)

# change

# Dictionary

Stu_info= {'num':'001','name':' Yuan Tiangang', 'sex':' male'}

Stu_info.update ({'sex':' female'})

Print (stu_info)

# list

List01= ['002' Li Chunfeng', 'male']

List01 [2] = 'unknown'

Print (list01)

# string

Str01='003\ t Wu Zetian\ t female'

Str01='003\ t Wu Zetian\ t male'

Print (str01)

Comprehensive case demonstration: making student information management system

Nameinfo= []

Def printMemu ():

Print ("20")

Print ("= = Student Management system V1.0 students =")

Print ("20")

Print ("1: add student information")

Print ("2: delete student information")

Print ("3: show student information")

Print ("4: exit the system")

Def add ():

Num=input ("Please enter student ID:")

Nmae=input ("Please enter student name:")

Sex=input ("Please enter student gender (male / female)")

NewInfo= {}

NewInfo ['num'] = num

NewInfo ['name'] = nmae

NewInfo ['sex'] = sex

Nameinfo.append (newInfo)

Print (nameinfo)

Def show ():

Print ("20")

Print ("Student information is as follows:")

Print ("20")

Print (nameinfo)

Def delete ():

Del_num=input ("Please enter the student ID to delete:")

For i in nameinfo:

If I ['num'] = = del_num:

Nameinfo.remove (I)

While True:

PrintMemu ()

Chose=int (input ("Please enter the number corresponding to the function"))

If (chose==1):

Print ("1: add student information")

Add ()

If (chose==2): print ("2: delete student information") delete () if (chose==3): print ("3: display student information") show () if (chose==4): print ("4: quit the system") break Thank you for reading! This is the end of this article on "what are the basic operations of python sequences?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report