Fortune Telling Collection - Zodiac Guide - Basic operation of python list

Basic operation of python list

A list is an ordered and changeable collection. In Python, lists are written in square brackets.

List is a data type in python, which consists of an ordered set of elements. Supports characters, numbers, strings, and even lists (lists are nested), and elements are separated by commas.

The list is identified by [].

Definition of list:

(1) Define an empty list:

list_stu 1 = [].

list_stu2 = list().

(2) Define the list with student information:

List_stu 1 = ['Zhang San', 19,' Male',' Changsha', 1343 43434] # Use a list to store the basic information of a student.

print(list_stu 1).

List_stu2 = [[' Zhang San', 19,' male',' Changsha', 1343 43434], # Nesting the information of multiple students through the list.

['Li Si', 18,' male',' Wuhan', 135353535].

['Wang Wu', 22,' female',' Shanghai', 136363636]].

print(list_stu2).

['Zhang San', 19,' male',' Changsha', 134343434].

[['Zhang San', 19,' male',' Changsha', 1343 43434], ['Li Si', 18,' male',' Wuhan',1353 53434]