Can anyone tell me how can I get the length of a string without using the len()
function or any string methods. Please anyone tell me as I'm tapping my head madly for the answer.
Thank you.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Here's a way to do it by counting the number of occurences of the empty string within the string:
Since
"".count("")
returns 1, you have to subtract 1 to get the string's length.easy:
I'm new to python but i would say that you can get the length of the string with a for loop, for example instead of:
do this:
This code verifies the length of a string by counting until ""(end of the string ).If the string reaches an end, the loop breaks and will return the final length of the string.
Not very efficient but very concise:
Make a file-like object from the string, read the entire object, then tell your offset: