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
newbieAuggie2019 and buran 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
  How can i limit length string? perrfect 3 141 Feb-10-2020, 04:52 PM
Last Post: Jendker
  Manipulating index value, what is wrong with this code? Emun 1 87 Feb-05-2020, 07:18 AM
Last Post: perfringo
  What is wrong with this strings comparison minh 3 163 Jan-31-2020, 07:42 PM
Last Post: minh
  where did i go wrong SufiyanSadiq 1 114 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 150 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  tell me what's wrong with my code? codingisannoyingaf 6 233 Jan-02-2020, 11:28 AM
Last Post: adaomacarl
  Saves the data in the wrong format Hennie 1 153 Jan-01-2020, 03:40 PM
Last Post: sandeep_ganga
  What is wrong with my chemistry code? mimimycin 9 284 Dec-30-2019, 06:43 PM
Last Post: mimimycin
  I don't know what's wrong with this code [Python Console] H0M1C1D4L_P1G 6 202 Dec-22-2019, 10:27 PM
Last Post: snippsat
  AttributeError: 'NoneType' object has no attribute 'label' : What's wrong ? Etienne17 1 306 Dec-13-2019, 06:57 PM
Last Post: ibreeden

Forum Jump:


Users browsing this thread: 1 Guest(s)