PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""Is a class iterable in python
(can we iterate through a class)?
https://www.sololearn.com/Discuss/3318311/?ref=app"""
class Meta(type):
def __iter__(cls):
"""you can implement your own
method based on cls.value type or
some stuff"""
return iter(cls.value)
class IterableClass(metaclass=Meta):
value = None
IterableClass.value = "SoloLearn"
[print(k)for k in IterableClass]
# Vitaly Sokol, Feb 21, 2025.
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run