tuples

  • Tuples are similar to lists. Different tuples cannot be changed after they are defined. Lists can be changed.
  • Tuples are bracketed and lists are bracketed.
#tuple
# tuple definition
students = ("Zhang"."Bill"."Fifty")
Copy the code

Common List Operations

  • Print the element
#tuple
# tuple definition
students = ("Zhang"."Bill"."Fifty")

print(students[0])
print(students[1])
print(students[2])
Copy the code

Results of the above code:

  • Traverse elements
#tuple
# tuple definition
students = ("Zhang"."Bill"."Fifty")

for i in students:
    print(i)
While I < len(students): print(students[I]) I +=1"
Copy the code

Results of the above code:

  • statistical
#tuple
# tuple definition
students = ("Zhang"."Bill"."Fifty"."Bill")
print("There are % D of lees."%students.count("Bill"))
Copy the code

Results of the above code:

  • Check index
#tuple
# tuple definition
students = ("Zhang"."Bill"."Fifty"."Bill")
print("King five's index is % D"%students.index("Fifty"))
Copy the code

Results of the above code: