开发者

how close a.lower() in python to a->lower() in C++

Since variables point to objects in python, I guess, and it is a reference. Suppose a is a string and can I fully interpret a.lower() in python as a replacement for C/C++ a->lower() on a pointer to char*? I know these are different languages, but trying to relate similar concepts so that it is easier to understand.

Edit: Suppose I have a class th开发者_JS百科at implements a string that has a lower method.


char* does not have a lower() method. Your comparison is invalid.

Calling str.lower() is like calling tolower(3) on each character in turn and returning the new string.


you say:

Suppose I have a class that implements a string that has a lower method.

but then it gets very difficult to guess what the implementation of the method does.

The main difference you may have in C++ / Python strings is in-place modification: Python strings are not mutable, whereas C++ strings are. So your string.lower() C++ method may be changing the string in place and not returning a new string which is what the Python version does.

E.g. Boost string library has a to_lower() method which does in place modification (http://www.boost.org/doc/libs/1_47_0/doc/html/boost/algorithm/to_lower.html)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜