Python Forum

Full Version: / token in function parameterlist
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm learning python by just reading documentation after I decided that none of the books and courses out there are good enough. Here's the question in the funcdef documentation we have

funcdef                   ::=  [decorators] "def" funcname "(" [parameter_list] ")"
                               ["->" expression] ":" suite
decorators                ::=  decorator+
decorator                 ::=  "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE
dotted_name               ::=  identifier ("." identifier)*
parameter_list            ::=  defparameter ("," defparameter)* "," "/" ["," [parameter_list_no_posonly]]
                                 | parameter_list_no_posonly
parameter_list_no_posonly ::=  defparameter ("," defparameter)* ["," [parameter_list_starargs]]
                               | parameter_list_starargs
parameter_list_starargs   ::=  "*" [parameter] ("," defparameter)* ["," ["**" parameter [","]]]
                               | "**" parameter [","]
parameter                 ::=  identifier [":" expression]
defparameter              ::=  parameter ["=" expression]
funcname                  ::=  identifier
on the parameter_list line, you see "/" but there is no explanation of its effect anywhere...
I wrote the function bellow:
def f(t: int = 2, /):
  return t
This function acted the same way it would act if '/' wasn't in its parameter list. So what is the '/' about?