Iterating through Strings - Pytho course problem

Hello, I am working on the “Iterating through Strings” and I got to the solution, but when I want to print it, it prints the Memory address instead of the value. This is what I got:

def get_length(string):

length = 0

for i in string:

length += 1

return length



And I get this: <function get_length at 0x7fb76e61fe18>

Which is what we would expect. Python is telling us that get_length is a function. What we want to print is the value that function returns. This means we can print directly a call expression, or print a saved call expression. The key here is the return value of the function.

print (get_length("Diego"))


diego = get_length("Diego")
print (diego)

In each case the print() function is being given a value rather than a reference to some object that cannot be literally represented.

Values such as numbers, strings, lists, dictionaries, booleans and None can be represented in a literal sense in the standard output. Functions and class objects are a little more involved. We saw the output when we tried to print a function reference…


That you very much for your reply! Exactly what I was looking for. :slight_smile:

1 Like