Added lecture 2026113
This commit is contained in:
parent
be356ccb59
commit
5b630435ae
27 changed files with 738 additions and 0 deletions
|
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# List element manipulation.
|
||||
|
||||
dogNames = [ "harry", "Shenanigans","katrina","Tanner","Yukon Jack", "Colorado","Mandy"]
|
||||
dogNames2 = ["Oscar", "Rusty"]
|
||||
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
|
||||
print("Append element Rusty to the list.")
|
||||
dogNames.append("Rusty")
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print("\n")
|
||||
|
||||
# Reset dogNames back to the original list
|
||||
dogNames = [ "harry", "Shenanigans","katrina","Tanner","Yukon Jack", "Colorado","Mandy"]
|
||||
# Insert a value into the list
|
||||
print("Insert a list into position #2")
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print (dogNames2," length = ",len(dogNames2))
|
||||
dogNames.insert(2,dogNames2)
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print("\n")
|
||||
|
||||
# Reset dogNames back to the original list
|
||||
dogNames = [ "harry", "Shenanigans","katrina","Tanner","Yukon Jack", "Colorado","Mandy"]
|
||||
# Insert a list into the list
|
||||
print("Append a list at the end")
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print (dogNames2," length = ",len(dogNames2))
|
||||
dogNames.append(dogNames2)
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print("\n")
|
||||
|
||||
|
||||
# Reset dogNames back to the original list
|
||||
dogNames = [ "harry", "Shenanigans","katrina","Tanner","Yukon Jack", "Colorado","Mandy"]
|
||||
# Insert a list into the list
|
||||
print("Extend a list at the end. This expands the list at the end of the first list.")
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print (dogNames2," length = ",len(dogNames2))
|
||||
dogNames.extend(dogNames2)
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print("\n")
|
||||
|
||||
|
||||
# Reset dogNames back to the original list
|
||||
dogNames = [ "harry", "Shenanigans","katrina","Tanner","Yukon Jack", "Colorado","Mandy"]
|
||||
# Insert a list into the list
|
||||
print("Remove the value katrina from the list. ")
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
dogNames.remove("katrina")
|
||||
print (dogNames," length = ",len(dogNames))
|
||||
print("\n")
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue