Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the basic operations of python sequences

Shulou Source: shulou.com Published: 2022-06-03 04:30:15 09月14日 Update

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!

Tags: Students information Wu Zetian input sequence variable system Tiangang dictionary character string Chunfeng basic operation content function student number more management system article management Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Microsoft Docker Apple