Bottom Page

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- 
>>> 
Quote
#2
what encoding is this? You can encode it via encode() method
>>> len('lòng')
5
>>> len('lòng'.encode('ascii','ignore'))
4
buran and newbieAuggie2019 like this post
Quote
#3
Try this
>>> w = 'l\u00F2ng'
>>> w
'lòng'
>>> print(w)
lòng
>>> len(w)
4
Your initial string could be a mojibake.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Wrong pip3 python location or new Version 007fred50 1 141 Apr-02-2020, 02:36 PM
Last Post: philgoetz
  Help ANSI character and python... sid4g 2 103 Mar-19-2020, 06:08 PM
Last Post: sid4g
  Class Instances called in the wrong order IanIous 4 164 Mar-06-2020, 02:16 PM
Last Post: IanIous
  compiled cpython output wrong version bigrockcrasher 0 106 Feb-25-2020, 06:31 PM
Last Post: bigrockcrasher
  How can i limit length string? perrfect 3 170 Feb-10-2020, 04:52 PM
Last Post: Jendker
  Manipulating index value, what is wrong with this code? Emun 1 127 Feb-05-2020, 07:18 AM
Last Post: perfringo
  What is wrong with this strings comparison minh 3 190 Jan-31-2020, 07:42 PM
Last Post: minh
  where did i go wrong SufiyanSadiq 1 133 Jan-31-2020, 06:12 PM
Last Post: Gribouillis
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 207 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  tell me what's wrong with my code? codingisannoyingaf 6 261 Jan-02-2020, 11:28 AM
Last Post: adaomacarl

Forum Jump:


Users browsing this thread: 1 Guest(s)