Added code for lecture 2026-11-10
This commit is contained in:
parent
5b630435ae
commit
07b9e54bf0
52 changed files with 1248 additions and 1 deletions
33
lecture20261110/listmethods/list05MethodCount.py
Normal file
33
lecture20261110/listmethods/list05MethodCount.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
# https://www.w3schools.com/python/python_ref_list.asp
|
||||
# https://www.quackit.com/python/reference/python_3_list_methods.cfm
|
||||
|
||||
programMessage = '''
|
||||
The count() method counts the number of elements in a list.
|
||||
|
||||
'''
|
||||
|
||||
print(programMessage)
|
||||
|
||||
|
||||
basicList = [1, 34, 99, 87, 14, 1, 34, 1,87 ]
|
||||
print(f"Example list {basicList}")
|
||||
|
||||
myValue = 1
|
||||
counter = basicList.count(myValue)
|
||||
print(f"The number of '{myValue}' items is {counter}")
|
||||
|
||||
myValue = 34
|
||||
counter = basicList.count(myValue)
|
||||
print(f"The number of '{myValue}' items is {counter}")
|
||||
|
||||
myValue = 87
|
||||
counter = basicList.count(myValue)
|
||||
print(f"The number of '{myValue}' items is {counter}")
|
||||
|
||||
myValue = 314
|
||||
counter = basicList.count(myValue)
|
||||
print(f"The number of '{myValue}' items is {counter}")
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue