Add null character to string in python

2020-08-25 05:00发布

问题:

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:

List comprehension.

[c + '\0' for c in S]

But it smells like you want UTF-16LE instead.

u'teststring'.encode('utf-16le')


标签: python