0

Can someone help me work this out on (Python 3.9.6) please? This works fine:

class Y:
    a = 'aaa'
    c = tuple(x+x for x in a)

This gives an exception:

class Z:
    a = 'aaa'
    b = 'bbb'
    c = tuple(x+y for x in a for y in b)
    
Traceback (most recent call last):
  File "<pyshell#36>", line 1, in <module>
    class Z:
  File "<pyshell#36>", line 4, in Z
    c = tuple(x+y for x in a for y in b)
  File "<pyshell#36>", line 4, in <genexpr>
    c = tuple(x+y for x in a for y in b)
NameError: name 'b' is not defined
Robert
  • 3
  • 1

0 Answers0