String length without len function

前端 未结 17 1278
逝去的感伤
逝去的感伤 2020-12-10 21:29

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 ma

17条回答
  •  感情败类
    2020-12-10 21:55

    Make a file-like object from the string, read the entire object, then tell your offset:

    >>> import StringIO
    >>> ss = StringIO.StringIO("ABCDEFGHIJ")
    >>> ss.read()
    'ABCDEFGHIJ'
    >>> ss.tell()
    10
    

提交回复
热议问题