What's happening here? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: What's happening here? (/thread-39495.html) |
What's happening here? - jesse68 - Feb-27-2023 Hi, I'm not understanding what's happening here? print ( int('101', 2)) # Equals 5However... print ( int('101)) # Equals 101I guess I don't know what the comma is doing. Thanks much. RE: What's happening here? - deanhystad - Feb-27-2023 The comma is seperating the argumemts '101' and 2. If you want to know what the arguments do, read the documentation for int(). RE: What's happening here? - jesse68 - Feb-27-2023 So it's base 2. This is wrong I'm sure but I'm reading.. 1 0 1 2 0 2 = 4 Still looking.. RE: What's happening here? - Gribouillis - Feb-27-2023 It's only simple maths >>> int('101', 2) == 1 * 2**2 + 0 * 2**1 + 1 * 2**0 True >>> int('101') == 1 * 10**2 + 0 * 10**1 + 1 * 10**0 True >>> |