I have list as:
['t','e','s','t','s','t','r','i','n','g']
How to add null character after each string t
, e
, s
, t
, s
, t
, r
, i
, n
, g
?
1 Answer. Show activity on this post. Isspace function will search the string only till it encounters the NULL(\0) character. hence compare the string elements with the space (or ASCII value) to recognize the space and replace it with a '\0' character.
Python uses the keyword None to define null objects and variables. While None does serve some of the same purposes as null in other languages, it's another beast entirely. As the null in Python, None is not defined to be 0 or any other value. In Python, None is an object and a first-class citizen!
There is no end-of-string character in Python, at least not one that is exposed and it would be implementation dependent. String objects maintain their own length and it is not something that you need to be concerned with.
It's an indicator to the format method that you want it to be replaced by the first (index zero) parameter of format. ( eg "2 + 2 = {0}".format(4) )
List comprehension.
[c + '\0' for c in S]
But it smells like you want UTF-16LE instead.
u'teststring'.encode('utf-16le')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With