+ 2

# I need help from a guru 🤭

Why is the answer "0": What is the output from the code? ages = [23, 11, 18, 75, 99] p = ages.count(99) - ages.count(11) print(p)

5 Antworten

+ 4

Please use appropriate tag. In this case, Python and count
https://www.sololearn.com/Discuss/1316935/?ref=app

+ 7

count function of the list basically gives you how many times the data occur in the list.
ages.count(99) is 1 because 99 occurs in the list only once or you can say the frequency of 99 in ages list is 1.
ages.count(11) is also occur in ages list 1.
that's why when you minus ages.count(99) from ages.count(11) gives you value 0 because both have the same value.

+ 6

list.count(x) returns the frequency of specified element x found within the list.
The list you provided contains one 99 and one 11, so ages.count(99) and ages.count(11) both returns 1. 1-1 is 0.
Ref:
https://docs.python.org/3/tutorial/datastructures.html

+ 3

Oh, I got that thank you so much☺️

+ 1

1-1=0