How to make a function which can take second required argument ?
In range(start, stop, step) we can directly pass `stop` argument because start, and step are optional if we pass start and stop both i.e. range(start, stop) then start is the first positional argument and stop is at second place. I want to make this type of function where i can pass second argument directly. I try to create it but if I make start optional then I have to make it keyword arg and set it to None and No positional arg can follow kwarg. How can I do it?
Positional arg cannot exist between optional arg. Whats going on behind the scene is some kind of function's overloading. this could be def _range(start, stop, step) : X = range.func_code_.co_argcount if x == 1: stop = start return range(0, stop, 1)
python is different than other languages , it require to use the optional arguments after the required arguments . so this will work hopefully def fn(req1, req2, opt1="A", opt2="B") Hope this what u're lookin for
You can do This : def fn(opt="default", req, opt2="default2")
Med Amine Fh this is wrong in python's syntax
Med Amine Fh I have read those questions but My question is different from these. I know how to use optional args in python. But it is not working in that way which I want it to work
I know that, but python also has range(start, stop, step) function where start is optional, stop is required and step is also optional. So how they have put one positional arg in between two optional args. How can I achieve that same thing