Convert string to unicode in Python

0 votes
Write a program to read an ASCII string and to convert it to a unicode string encoded by utf-8.
Jul 23, 2019 in Python by Rishi
12,591 views

1 answer to this question.

0 votes

Suppose you have a string in ASCII form you can encode it to utf-8 or utf-16 using encode function, please go through the below code snippet to do the same,

>>> x="String"
>>> x.encode('utf-8')
b'String'
>>> x.encode('utf-16')
b'\xff\xfeS\x00t\x00r\x00i\x00n\x00g\x00'


Hope this helps!!

If you need to learn more about Python, It's recommended to join Python Certification Training today.

Thanks!

answered Jul 23, 2019 by Gani

Related Questions In Python

0 votes
1 answer

How to convert date string to date object in python?

Use this :-  >>> datetime.datetime.strptime('24052010', "%d%m%Y").date() datetime.date(2010, 5, 24) Hope ...READ MORE

answered Oct 22, 2018 in Python by Priyaj
• 58,090 points
10,972 views
0 votes
1 answer

Python: convert string to unicode

Suppose you have a string in ASCII form ...READ MORE

answered Jul 10, 2019 in Python by Olivia
1,350 views
0 votes
1 answer

What is the best way to remove accents in a Python unicode string?

Hello @kartik, Some languages have combining diacritics as ...READ MORE

answered May 11, 2020 in Python by Niroj
• 82,880 points
6,780 views
0 votes
1 answer

How to convert string to date in python with different algorithms ?

Hello @ pagarsach, You can convert a string to ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,880 points
579 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,414 views
0 votes
1 answer

How to convert string in Pandas Series to lower case?

Suppose you have the series stored in ...READ MORE

answered May 13, 2019 in Python by Raj
2,287 views
0 votes
1 answer

Is there a string 'contains' in python?

In this case, you can use the ...READ MORE

answered Sep 25, 2018 in Python by SDeb
• 13,300 points
504 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP