An error occurs if _suits is not defined even though it is already defined
class Card: _suits = ['♠', '♥', '♦', '♣'] _number = [i for i in range (1, 14)] card =  card = [[(_suits [i], _number [j]) for i in range (4)] for j in range (13)] Code
Answer # 1
The code as in the question won't work because there are limited places where you can access class variables.
For example, the desired function can be realized by cutting it into another function as follows.
def create_set (): suits = ['♠', '♥', '♦', '♣'] number = [i for i in range (1, 14)] return [[(suits [i], number [j]) for i in range (4)] for j in range (13)] class Card: card = create_set ()
Or move to the constructor side.
class Card: _suits = ['♠', '♥', '♦', '♣'] _number = [i for i in range (1, 14)] def __init __ (self): self.card = [[(self._suits [i], self._number [j]) for i in range (4)] for j in range (13)]
Answer # 2
wrong Requested deletion per answer
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- python 3x - typeerror: 'method' object is not subscriptable
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - unresolved reference comes out in kotlin