Python Strings & Console Output


this is my code

Write your code below, starting on line 3!

my_string = "hello my name is josh"

print len.my_string
print my_string.upper()

this is the error
Traceback (most recent call last):
File "python", line 5, in
AttributeError: 'builtin_function_or_method' object has no attribute 'my_string'

please help


my_string = "cat"
print len (my_string)
print my_string.upper()


The code by @ajaxmaster75260 is the proper one @theblaster3000.
For explanation the error in your code is the the len() function used to get the length of a string takes one argument and that argument is the variable where the string is stored.
so you need to pas your variable my_string to the len() function as done by @ajaxmaster75260 i.e.
print len (my_string).
Hope this explanation helps :wink:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.