Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does def method (parameter = None) mean? [closed]

Tags:

python

class Employee:
    def __init__(self, lastname, firstname = None):
        self.lastname = lastname
        self.firstname = firstname

What does firstname = None in the second row mean?

like image 302
Koji Sugano Avatar asked Jul 26 '26 18:07

Koji Sugano


1 Answers

This allows you to call this function and omit that particular parameter. If you do omit it, it will default to the listed value of None. If you do pass a value, it will be used.

>>> def f(arg='a'):
...     print(arg)
...
>>> f()
a
>>> f('b')
b
like image 55
TigerhawkT3 Avatar answered Jul 28 '26 07:07

TigerhawkT3