Yong Cui
Nov 15, 2021

--

OK. You can do this:

class Student:

def __init__(self, name, subjects=None):

self.name = name

self.subjects = subjects or ["maths", "physics"]

self.subjects = subjects or ["maths", "physics"] is equivalent to

if subjects:

self.subjects = subjects:

else:

self.subjects = ["maths", "physics"]

--

--

Yong Cui
Yong Cui

Written by Yong Cui

Work at the nexus of biomedicine, data science & mobile dev. Author of Python How-to by Manning (https://www.manning.com/books/python-how-to).

No responses yet