“round” rounds Python numbers: Remember, .5 goes to the nearest *even* value:
Want to make Python numbers more readable? Use _ between digits (not at the start or end):
Have you ever wondered about bitwise operations in Python? They’re not that common nowadays, but they are still in the language, and can be useful in some cases. A subscriber to my “Better developers” newsletter asked me to explain these. I made a video doing so: Here’s the Jupyter notebook I used in creating the…
In Python, we know that we can add two integers together: >> 2 + 2 4 And of course, we can add two strings together: >> ‘a’ + ‘b’ ‘ab’ We can even add two lists together: >> [1,2,3] + [4,5,6] [1, 2, 3, 4, 5, 6] But what happens when you add two booleans…
I’m in Shanghai, and before I left to teach this morning, I decided to check the weather. I knew that it would be hot, but I wanted to double-check that it wasn’t going to rain — a rarity during Israeli summers, but not too unusual in Shanghai. I entered “shanghai weather” into DuckDuckGo, and got…