X Tutup
7 Comments
User's avatar
⭠ Return to thread
Peter Heller's avatar

Why use the double quote def __init__(self, name=""): instead of None def __init__(self, name=None): ?

Eric Matthes's avatar

That's a really interesting question. In a simple example, it won't make much difference. In a real-world context, it depends on what you might do with that value. Using an empty string means any string method that's called on name will work; if you used None and called a string method, such as name.title(), you'd get an error.

Using None would allow you to determine if a value was passed. You could check `if name is None`, and then deal with a situation where a name was not passed. Even in that case, a test of `if not name` is probably going to be sufficient.

    X Tutup