+ 1
string formatting
Hello, everyone, I was doing the programming assignments and came across this line "("x & y = {0:b}b".format(x&y))'' which I couldn't get it can anyone explain to me as I know that this is string formating. Thank you
2 odpowiedzi
+ 4
& operatir or and binary operator. When used you have the follow rules
In & (binary and operator)
1 & 1 = 1
0 & 1 = 0
0 & 0 = 0
So
0b1100100 # 100
0b1000110 # 70
0b1000100 #100 & 70
when you have {0:b} you specifing to print in binary and the b outiside it's just to sinalize in output that is binary number like 100b equals 4 in decimal. We can use the 0b notation too like i did.
You can check for yourself here
https://code.sololearn.com/cQENwuhpEtxh/?ref=app
0
What the hell !