In this example we convert a positive number to binary using bin() function and then count all the 1s in the obtained string. bin() function returns a binary representation in a format 0b101 for a number 5, therefore we cut the "0b" part using [2:] syntax.
#python #numbers #binary