======= Convert Decimal to Binary in Python ========
my_int =10;#Method 1: using bin
n1 =bin(my_int).replace("0b","")#1010or n1 =bin(my_int)[2:]#Method 2: using format
n2 ="{0:b}".format(my_int)or n2 =format(my_int,'b')#1010
defconvert_to_binary(number:int):if number ==None:return"Invalid input"eliftype(number)==float:return"Float is not Handled"returnformat(number,"010b")print(convert_to_binary(None))print(convert_to_binary(100))print(convert_to_binary(6.5))
print(str(1))# convert number to stringprint(int("1"))# convert string to intprint(float(1))# convert int to floatprint(list('hello'))# convert string to listprint(tuple('hello'))# convert string to tupleprint(list((1,2,3)))# convert tuple to listprint(tuple([1,2,3]))# convert list to tupleprint(bool(1))# convert a number to booleanprint(bool(0))# convert a number to booleanprint(bool(""))# convert a string to booleanprint(bool("data"))# convert string to booleanprint(bin(10))# convert an integer to a binary stringprint(hex(10))# convert an integer to a hex stringprint(oct(10))# convert an integer to an octal string
number =5print('The binary equivalent of 5 is:',bin(number))# output - The binary equivalent of 5 is: 0b101# "0b" indicates that this is a binary number# 101 is the number (2**2 * 1) + (2**1 * 0) + (2**0 * 1) = 5