Newby Python help needed with functions

Andrew Berg bahamutzero8825 at gmail.com
Fri Jun 3 11:10:49 EDT 2011


On 2011.06.03 09:42 AM, Cathy James wrote:
> I need a jolt here with my python excercise, please somebody!! How can
> I make my functions work correctly? I tried below but I get the
> following error:
>
> if f_dict[capitalize]:
>
> KeyError: <function capitalize at 0x00AE12B8>
>
...
>
>  def capitalize (s):
>     """capitalize accepts a string parameter and applies the
> capitalize() method"""
>     s.capitalize()
>
...
>
>     f_dict = {'capitalize': 'capitalize(s)',
>
Your capitalize() function doesn't return anything, therefore
f_dict[capitalize] won't contain anything. Your string s will still be
changed (inside the function) when the function is called, but there is
still no value associated with capitalize().
Also, capitalize in f_dict[capitalize] points to the capitalize function
object instead of the entry in the dictionary. You should call
f_dict['capitalize'] instead.



More information about the Python-list mailing list