| Section | Video Links |
|---|---|
| Composite Overview | ![]() |
| Composite Use Case | ![]() |
| Conditional Expressions | ![]() |
... Refer to Design Patterns In Python website to read textual content.
... Refer to Design Patterns In Python website to read textual content.
... Refer to Design Patterns In Python website to read textual content.
python ./composite/composite_concept.py
LEAF_A id:2050574298848
LEAF_B id:2050574298656
COMPOSITE_1 id:2050574298272
COMPOSITE_2 id:2050574298128
<Leaf> id:2050574298656 Parent: None
<Composite> id:2050574298128 Parent: None Components:2
<Leaf> id:2050574298848 Parent: 2050574298128
<Composite> id:2050574298272 Parent: 2050574298128 Components:0... Refer to Design Patterns In Python website to read textual content.
python ./composite/client.py
<DIR> root id:2028913323984 Components: 4
..<FILE> abc.txt id:2028913323888 Parent: 2028913323984
..<FILE> 123.txt id:2028913323792 Parent: 2028913323984
..<DIR> folder_a id:2028913432848 Components: 1
....<FILE> xyz.txt id:2028913433088 Parent: 2028913432848
..<DIR> folder_b id:2028913433184 Components: 1
....<FILE> 456.txt id:2028913434432 Parent: 2028913433184
<DIR> root id:2028913323984 Components: 3
..<FILE> abc.txt id:2028913323888 Parent: 2028913323984
..<FILE> 123.txt id:2028913323792 Parent: 2028913323984
..<DIR> folder_b id:2028913433184 Components: 2
....<FILE> 456.txt id:2028913434432 Parent: 2028913433184
....<DIR> folder_a id:2028913432848 Components: 1
......<FILE> xyz.txt id:2028913433088 Parent: 2028913432848In /composite/composite_concept.py, there are two conditional expressions.
Conditional expressions an alternate form of if/else statement.
id(self.reference_to_parent) if self.reference_to_parent is not None else NoneIf the self.reference_to_parent is not None, it will return the memory address (id) of self.reference_to_parent, otherwise it returns None.
This conditional expression follows the format
value_if_true if condition else value_if_falseeg,
SUN = "bright"
SUN_IS_BRIGHT = True if SUN == "bright" else False
print(SUN_IS_BRIGHT)or
ICE_IS_COLD = True
ICE_TEMPERATURE = "cold" if ICE_IS_COLD == True else "hot"
print(ICE_TEMPERATURE)or
CURRENT_VALUE = 99
DANGER = 100
ALERTING = True if CURRENT_VALUE >= DANGER else False
print(ALERTING)Visit https://docs.python.org/3/reference/expressions.html#conditional-expressions for more examples of conditional expressions.
... Refer to Design Patterns In Python website to read textual content.



