Questions related to positional-only parameters in Python 3.8+, described in PEP570.
Questions tagged [pep570]
8 questions
10
votes
2 answers
Why use positional-only parameters in Python 3.8+?
A new "positional-only parameters" syntax has been introduced in 3.8.
From Positional-only parameters in the documentation:
There is new syntax (/) to indicate that some function parameters must
be specified positionally (i.e., cannot be used as…

Gulzar
- 23,452
- 27
- 113
- 201
7
votes
2 answers
How to create a python function which take only positional arguments and no keyword arguments?
A lot of inbuilt functions in python don't take keyword arguments. For example, the chr function.
>>> help(chr)
Help on built-in function chr in module builtins:
chr(i, /)
Return a Unicode string of one character with ordinal i; 0 <= i <=…

Diptangsu Goswami
- 5,554
- 3
- 25
- 36
6
votes
3 answers
How to implement "positional-only parameter" in a user defined function in python?
How can I implement "positional-only parameter" for a function that is user defined in python?
def fun(a, b, /):
print(a**b)
fun(5,2) # 25
fun(a=5, b=2) # should show error

Damodara Sahu
- 115
- 1
- 8
4
votes
2 answers
syntax error when using forward slash to define positional only arguments
I'm following the python tutorial here.
I'm trying to define a function with positional only arguments and I get a invalid syntax error
I've tried both the command line interpreter and putting the definition into a file
My definition looks like…

masc_and_cheese
- 51
- 2
2
votes
1 answer
Positional only parameters compatibility with python 3.7
I want to use the new positional only arguments syntax defined in PEP570, but I also want to maintain compatibility with python 3.7 (directly running the script with def f(a, /, b): directly results in a syntax error). Is there anyway to do this?
If…

Mayoi
- 315
- 1
- 2
- 6
2
votes
1 answer
How to call a function with positional-only parameters given an arguments dictionary?
Previously I've used Signature.bind(argument_dict) to turn argument dictionary into BoundArguments object that has .args and .kwargs that can be passed to a function.
def foo(a: str, b: str, c: str): ...
argument_dict= {"a": "A", "c": "C", "b":…

Ark-kun
- 6,358
- 2
- 34
- 70
0
votes
2 answers
Corner case with positional-only parameters in Python 3.8?
I am fiddling around with positional-only parameters as specified in PEP 570 and introduced with Python 3.8, and I was just wondering about a specific corner case.
Let's say I define a function as follows (no matter whether that is good design or…

hjs
- 11
- 3
-3
votes
3 answers
What does Positional-only parameters do in Python 3.8?
What below python code does?
def pow(x, y, z=None, /):
r = x**y
if z is not None:
r %= z
return r

codingLover
- 3
- 1