Python Forum
python gives wrong string length and wrong character
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python gives wrong string length and wrong character
#1
Below python gives wrong string length. The Length should be 4 and w[1] should be 'ò', but python give back letter 'o'. Please help.



>>> w ='lòng >>> w 'lòng' >>> print (w) lòng >>> len(w) 5 >>> for ch in w: ... print (ch + "-") ... l- o- - n- g- >>> 
Reply
#2
what encoding is this? You can encode it via encode() method
>>> len('lòng') 5 >>> len('lòng'.encode('ascii','ignore')) 4
Recommended Tutorials:
Reply
#3
Try this
>>> w = 'l\u00F2ng' >>> w 'lòng' >>> print(w) lòng >>> len(w) 4
Your initial string could be a mojibake.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo the python using issue,please help to check what is wrong with it Beginner_ 1 1,246 Nov-13-2024, 06:53 PM
Last Post: deanhystad
  python escaping character atom509 1 1,264 May-29-2024, 08:57 PM
Last Post: DeaD_EyE
  wrong entries in sqlite database and tkinter epsilondatum 2 2,289 Apr-23-2024, 04:48 PM
Last Post: epsilondatum
  I don't know what is wrong (Python and SQL connection) shereen 3 2,319 Apr-01-2024, 08:56 AM
Last Post: Pedroski55
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 1,811 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Is this a multiprocessing bug in Python - or am I doing something wrong? haimat 1 4,528 Oct-18-2023, 06:07 AM
Last Post: absalom1
  Python rule about the space character surrounding the equal sign ineuw 10 6,980 Sep-21-2023, 09:17 AM
Last Post: ineuw
  How do I handle escape character in parameter arguments in Python? JKR 6 8,182 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 7,536 Aug-13-2023, 12:16 AM
Last Post: cubangt
  Wrong type error rowan_bradley 6 3,744 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.