r/pythontips

Special mechanism of basic int() function

One can use int() function while converting string to an integer against a base integer.

int(number, base) #number can be anything between binary, octal, decimal, or hexadecimal and base is anything among 2, 8, 10, 16

e.g. binary_number = int("1010", 2) #Output: 10
hexadecimal_number = int("A", 16) #Output: 10

reddit.com

Docstrings as immutable variables

Just realized you can do:

def cat(): “orange”
print(cat.__doc__)

Not sure why you’d want to do this but this is a thing you can do

reddit.com
u/sugarw0000kie — 7 days ago