1

I am from a c background. started learning python few days ago. my question is what is the end of string notation in python. like we are having \0 in c. is there anything like that in python.

4
  • 2
    Why does this matter for a high-level programming like Python? Commented Oct 7, 2013 at 9:33
  • 1
    Python is not C and strings are objects not not simple pointers to some memory area. Commented Oct 7, 2013 at 9:34
  • Valid question but one that does not make much sense. Downvoted. Commented Oct 7, 2013 at 9:34
  • @user2799617 i mentioned that i am coming from c background. did not have much idea about python. to be clear about memory allocation in case of sting, i asked this question. Commented Oct 7, 2013 at 9:37

3 Answers 3

5

There isn't one. Python strings store the length of the string independent from the string contents.

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

Comments

2

There is nothing like that in Python. A string is simply a string. The following:

test = "Hello, world!"

is simply a string of 13 characters. It's a self-contained object and it knows how many character it contains, there is no need for an end-of-string notation.

Comments

1

Python's string management is internally a little more complex than that. Strings is a sequence type so that from a python coder's point of view it is more an array of characters than anything. (And so it has no terminating character but just a length property.)

If you must know: Internally python strings' data character arrays are null terminated. But the String object stores a couple of other properties as well. (e.g. the hash of the string for use as key in dictionaries.)

For more detailed info (especially for C coders) see here: http://www.laurentluce.com/posts/python-string-objects-implementation/

Comments