Python Default Arguments for functions

Sdílet
Vložit
  • čas přidán 13. 09. 2024
  • Looks at default formal parameters and how they can be used with keyword and positional arguments.

Komentáře • 8

  • @gloriousnoobs5456
    @gloriousnoobs5456 Před 7 lety +3

    this is absolutely fantastic
    the most clear explanation I've found on YT so far
    thank you

  • @vlyalcin
    @vlyalcin Před 6 lety +1

    This is exactly what I was looking for. Great video!

  • @SMajid--SMajid
    @SMajid--SMajid Před 8 lety +1

    This is such a neat explanation, thanks a lot!

  • @DarkLordAli95
    @DarkLordAli95 Před 8 lety +1

    THANKS!

  • @exabyte00
    @exabyte00 Před 8 lety +1

    Thanks man!

  • @nasrullahturke4480
    @nasrullahturke4480 Před 5 lety

    I was making notes of imp points from this videos and I just came across one point which I am not sure if we are missing in this video unless assumed to be self understood.
    When we have default arguments set and if we pass just one argument without using keyword then by default the argument passed will take the place of first argument.
    def multiple_display (message = 'default', times = 2):
    for I in range (times):
    print(message)
    multiple_display ('HELLO WORLD')
    Gives result as
    HELLO WORLD
    HELLO WORLD
    multiple_display (88)
    Gives result as
    88
    88
    Have I understood correct John.

    • @johnphilipjones
      @johnphilipjones  Před 5 lety +1

      As well as passing by keyword, arguments can be passed by position. So the 88 argument is passed to the formal parameter message replacing the 'default' string in the definition of the function. The second formal parameter in the function definition still keeps the integer value of 2. So 88 is printed twice.
      Best wishes
      Phil

    • @nasrullahturke4480
      @nasrullahturke4480 Před 5 lety

      @@johnphilipjones Thanks Phil☺