What is the meaning of a forward slash "/" in a Python method signature, as shown by help(foo)? [duplicate] What is the meaning of a forward slash "/" in a Python method signature, as shown by help(foo)? [duplicate] python python

What is the meaning of a forward slash "/" in a Python method signature, as shown by help(foo)? [duplicate]


As explained here, the '/' as an argument marks the end of arguments that are positional only (see here), i.e. arguments you can't use as keyword parameters. In the case of __eq__(self, value, /) the slash is at the end, which means that all arguments are marked as positional only while in the case of your __init__ only self, i.e. nothing, is positional only.

Edit:This was previously only used for built-in functions but since Python 3.8, you can use this in your own functions. The natural companion of / is * which allows to mark the beginning of keyword-only arguments. Example using both

# a, b are positional-only. e,f keyword-onlydef f(a, b, /, c, d, *, e, f):    print(a, b, c, d, e, f)# valid callf(10, 20, 30, d=40, e=50, f=60)# invalid calls:f(10, b=20, c=30, d=40, e=50, f=60)   # b cannot be a keyword argumentf(10, 20, 30, 40, 50, f=60)           # e must be a keyword argument