Python 3 Programming Tutorial - Function Parameter Defaults

Veröffentlicht am: 20 April 2014
auf dem Kanal: sentdex
193,300
1.6k

In the last tutorial, we explained what function parameters were, and that we could have an infinite amount of them. With this, we explained how having a lot of them could become troublesome and tedious for the programmer using the function. Luckily, there is a solution for this. Sometimes, it can make a lot of sense to make a complex function highly customize-able. That said, some people may want to use the function in it's simple... "default" ... form. Think about it like buying a car. Some people want to just buy the base model, with all the features that come by default from the factory. Other people want to customize their car in many different ways. Luckily, we allow people who want to customize their car the option to do it, but we do not ask every buyer of every car what kind of wheels they want, what brand of tire, what screws they want, what kind of leather seats by what brand, what windshield, what steering wheel, what lights... etc. This is just too much for some people and what they want to use the car for. Same goes for functions in programming.

So we have function parameter defaults, which allow the function's creator to set "default" values to the function parameters. This allows anyone to use a function with the default values, yet lets anyone who wishes to customize them the ability to specify different values.

When using defaults, any parameters with defaults should be the last ones listed in the function's parameters.

Sample code for this basics series: http://pythonprogramming.net/beginner...

Python 3 Programming tutorial Playlist:    • Why Python 3? Python 2 vs Python 3  

http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
  / sentdex  

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6


Auf dieser Seite können Sie das Online-Video Python 3 Programming Tutorial - Function Parameter Defaults mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer sentdex 20 April 2014 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 193,300 Mal angesehen und es wurde von 1.6 tausend den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!