Python Forum
variable not defined inside a list comprehension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable not defined inside a list comprehension
#1
Hello, in a program i have a class like this one but when in run the code i get that x is not defined, is this problem relative to list comprehension?
class MyClass:
    x = 8
    y = 9
    grid = [[0 for _ in range(x)] for _ in range(y)]
Error:
Traceback (most recent call last): File "<input>", line 1, in <module> File "<input>", line 4, in MyClass File "<input>", line 4, in <listcomp> NameError: name 'x' is not defined
Reply


Messages In This Thread
variable not defined inside a list comprehension - by Phidias618 - May-13-2023, 08:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  function defined inside a function Skaperen 2 2,480 May-13-2021, 01:04 AM
Last Post: Skaperen
  what's homogeneus items defined by list frank0903 5 2,435 Jun-25-2020, 11:26 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020