簡體   English   中英

難以理解 python 變量聲明

[英]Difficulty in understanding the python variable declaration

我是 Python 的新手,並試圖解碼一條線以移植到 Go。 在當前的 python 腳本中,我在大部分 class 下都遇到了這個聲明(dataValue)。

class Keys(object):
   AB1 = 0x0FF
   AB2 = 0x0A2
   dataValue = {'0xffff':None}

   @classmethod
   def _init(cls):
     for ke, vl in vars(cls).items():
       
  1. 什么是數據值? 0xffff 是鍵並保持 None 作為值嗎?
  2. vars(cls).items() 返回什么?
  3. @classmethod 意味着這個 class 密鑰只使用一次? (我遇到了很多@propoerty 的定義,@classmthods 這些關鍵字仍然讓我感到困惑)

試圖通過實際項目來理解這些概念。 提前致謝!

  1. dataValue是一個字典變量名稱,其中包含key:value'0xffff':None
  2. vars(cls).items() Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute https://docs.python.org/3/library/functions.html#vars .
  3. 一個 function 返回另一個 function,通常使用 @wrapper 語法作為 function 轉換應用。 Common examples for decorators are classmethod() and staticmethod() https://docs.python.org/3/glossary.html#term-decorator https://docs.python.org/3/library/functions.html#classmethod https://docs.python.org/3/library/functions.html#staticmethod

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM