0

hi

what's wrong with this code?? list = ['a','b','c','d','a','f','g','h','a'] print(len('a')) why it prints 1 instead of 3???

31st Aug 2021, 3:06 PM
Younes.Ebrahimi
6 Answers
+ 2
Because your text size is 1
31st Aug 2021, 3:10 PM
Vtec Fan
Vtec Fan - avatar
+ 1
Younes.Ebrahimi If you wanna print how many 'a' in list, you can write like that print(list.count('a'))
31st Aug 2021, 3:27 PM
Myo Thuzar
Myo Thuzar - avatar
0
so how should i write a program that says how many 'a' do we have in the list??
31st Aug 2021, 3:13 PM
Younes.Ebrahimi
0
In your code you asked to print the lenght for “a” which is one letter thus the output was 1 To find the number of an element in your list use the count method: print(list.count(“a”))
31st Aug 2021, 3:23 PM
Ahmad
Ahmad - avatar
0
thank you very much
31st Aug 2021, 3:26 PM
Younes.Ebrahimi
0
yes i solved it thank you guys
31st Aug 2021, 3:31 PM
Younes.Ebrahimi