Use:
import color
class Color(color.Color):
...
If this were Python 2.x, you would also want to derive color.Color from object, to make it a new-style class:
class Color(object):
...
This is not necessary in Python 3.x.
Answer from NPE on Stack OverflowCan someone please explain the difference between the append and extend functions in Python really quickly? Is it just that extend can add multiple items simultaneously, whereas append can only add one at a time? Can you also please include an example if you have the time?
Use:
import color
class Color(color.Color):
...
If this were Python 2.x, you would also want to derive color.Color from object, to make it a new-style class:
class Color(object):
...
This is not necessary in Python 3.x.
class MyParent:
def sayHi():
print('Mamma says hi')
from path.to.MyParent import MyParent
class ChildClass(MyParent):
pass
An instance of ChildClass will then inherit the sayHi() method.
.append() appends a single object at the end of the list:
>>> x = [1, 2, 3]
>>> x.append([4, 5])
>>> print(x)
[1, 2, 3, [4, 5]]
.extend() appends multiple objects that are taken from inside the specified iterable:
>>> x = [1, 2, 3]
>>> x.extend([4, 5])
>>> print(x)
[1, 2, 3, 4, 5]
.append() adds an element to a list,
whereas .extend() concatenates the first list with another list/iterable.
>>> xs = ['A', 'B']
>>> xs
['A', 'B']
>>> xs.append("D")
>>> xs
['A', 'B', 'D']
>>> xs.append(["E", "F"])
>>> xs
['A', 'B', 'D', ['E', 'F']]
>>> xs.insert(2, "C")
>>> xs
['A', 'B', 'C', 'D', ['E', 'F']]
>>> xs.extend(["G", "H"])
>>> xs
['A', 'B', 'C', 'D', ['E', 'F'], 'G', 'H']