0

Hello I am trying to build a class to clean a string, however I dont understand why I got the following output:

 python3 clean.py 
<bound method clean_string.split_func of <__main__.clean_string object at 0x7fb70486b0f0>>

My class looks as follows:

class clean_string:

    def __init__(self,cadena):
        self.replace_chars = {"á":"a","ó":"o"}
        self.cadena = cadena
    def split_func(self):
        return self.cadena.split(' ')

test_string = clean_string('this is a test')

However when I execute the code I only got the memory reference object:

print(test_string.split_func)
<bound method clean_string.split_func of <__main__.clean_string object at 0x7fb70486b0f0>>

I want to get the following output:

['this', 'is', 'a', 'test']

1 Answer 1

2

print(test_string.split_func)

This line prints what split_func is, which is a function. If you want to print what is returned by the function, you need to do print(test_string.split_func())

Without the parentheses at the end, it will print what split_func is, which is what you see.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.