Python Forum
python 3.8 and positional arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python 3.8 and positional arguments
#5
Explained with code using your whatever function:

In [6]: def whatever(my_cool_var=4 * 5 / 2): 
   ...:     print(my_cool_var) 
   ...:                                                                                          

In [7]: whatever()                                                                               
10.0

In [8]: whatever(2)                                                                              
2

In [9]: whatever(my_cool_var=2)                                                                  
2

In [10]: def whatever(my_cool_var=4 * 5 / 2, /): 
    ...:     print(my_cool_var) 
    ...:                                                                                         

In [11]: whatever(my_cool_var=2)                                                                 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-65f31df15028> in <module>
----> 1 whatever(my_cool_var=2)

TypeError: whatever() got some positional-only arguments passed as keyword arguments: 'my_cool_var'

In [12]: whatever(2)                                                                             
2

In [13]: whatever()                                                                              
10.0
This is interesting for library developers who want to enforce the use of positional arguments, followed by keyword-arguments.
Just read the PEP.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
python 3.8 and positional arguments - by vojo - Jun-10-2019, 03:12 PM
RE: python 3.8 and positional arguments - by DeaD_EyE - Jun-10-2019, 10:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 423 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  How do I handle escape character in parameter arguments in Python? JKR 6 1,178 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
Question log.exception() without arguments in old Python versions? cthart 5 1,177 Nov-19-2022, 07:09 PM
Last Post: Gribouillis
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,960 Oct-17-2022, 06:29 PM
Last Post: paulo79
  TypeError: missing 3 required positional arguments: wardancer84 9 10,939 Aug-19-2021, 04:27 PM
Last Post: deanhystad
  TypeError: max_value() missing 2 required positional arguments: 'alpha' and 'beta' Anldra12 2 4,226 May-15-2021, 04:15 PM
Last Post: Anldra12
  How to reuse positional arguments entered in terminal. rcmanu95 1 1,879 Jul-04-2020, 01:00 AM
Last Post: bowlofred
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 11,730 May-31-2020, 03:13 PM
Last Post: deanhystad
  TypeError: add() missing 2 required positional arguments NectDz 5 13,125 May-28-2020, 02:54 PM
Last Post: BitPythoner
  add() takes 2 positional arguments but 3 were given Man_from_India 3 5,808 Feb-10-2020, 05:08 PM
Last Post: Man_from_India

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020