Python Forum
Incrementing binary number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incrementing binary number
#3
(Nov-10-2017, 11:40 AM)DeaD_EyE Wrote: The method insert of lst_binary returns None. Just memorize, that methods which mutates the object, returns regularly None. Immutable objects return something, when you use a method. For example str.upper('Foo') returns a new object, because the object itself is not mutable. It's immutable.

Methods of lists like sort, insert and remove won't return the list itself. The list object is mutating.
Just do your modification to your list with insert and use return ''.join(lst_binary) to join the modified list.

Thanks for the reply. At last i thought about this way return '1' + ''.join(lst_binary), and it works as well.
Reply


Messages In This Thread
Incrementing binary number - by Danielk121 - Nov-10-2017, 10:34 AM
RE: Incrementing binary number - by DeaD_EyE - Nov-10-2017, 11:40 AM
RE: Incrementing binary number - by Danielk121 - Nov-10-2017, 12:04 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020