문제

"this is my string".myfunction(argument)

This is very simple in javascript. With the keyword this i can access to my string directly. Is that possible with python?

올바른 솔루션이 없습니다

다른 팁

You can inherit from str and define your own methods:

class myString(str):
    def my_method(self, ...):
        # ...

some_string = myString("StackOverflow")

print some_string.count("a") # method from string
print some_string.myMethod(...) # your defined method
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top