17

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
  • 4
    Why do you need to add the null character? Commented Aug 18, 2012 at 5:08

1 Answer 1

40

List comprehension.

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

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

u'teststring'.encode('utf-16le')
Sign up to request clarification or add additional context in comments.

4 Comments

Why use u character in first of string ?
that's all what I want to know
u indicates that the string is Unicode, e.g., u'teléfono'
For those reading and still unsure of the reason there is a 'u' prefix: This prefix is indeed useless in Python 3 as all strings are manipulated in Unicode UTF-8 format by default, but could be used on 2.7 to force UTF--8 format, the default being Ascii (or at least some monobyte code).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.