Help - Search - Members - Calendar
Full Version: Python Help!
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
jpd750
Keep in mind, I am VERY new to python. Im trying to do this:

There is a string method called 'count'. Write an invocation that counts the number of 'a's in banana.

How do I do the above syntactically in python.

Thanks
ShadowMage
Heres how you would do it. You would want to use the list function to make the letters list, then you could count.
CODE
wordlist = list("banana")

That will assign the variable wordlist to be an array, and that array will have all the letters in banana.

To count how many there are now, you could do:
CODE
print wordlist.count("a")


and that should output 3.

Hope this helps.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.