0
0

More than 1 year has passed since last update.

About python class constant and scope

Last updated at Posted at 2022-05-10
class Hoge:
    PRIORITY = 1
    def hoge(self,p=PRIORITY, priority=4): # not self.PRIORITY
        print(self.PRIORITY,p,priority)

print(Hoge.PRIORITY) # could not use PRIORITY
r = Hoge()
r.priority = 7
r.hoge()
r.hoge(3)
r.hoge(3,5)
r.hoge(2)
print(Hoge.PRIORITY,r.priority) # could not use PRIORITY
1
1 1 4
1 3 4
1 3 5
1 2 4
1 7
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0