Add Null Character to String in Python

Add Null Character to String in Python

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

1 Answer

List comprehension.

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.