Package.Name来自哪里?

huangapple go评论190阅读模式
英文:

Where does Package.Name come from?

问题

[package.name]只是键的变量名,package.name是从package对象中获取的。

英文:

In the add_packages method below, is [package.name] just a variable name for the key? Where do we get package.name from?

  1. class Repository:
  2. def __init__(self):
  3. self.packages = {}
  4. def add_package(self, package):
  5. self.packages[package.name] = package

答案1

得分: 1

package.name 是一个 表达式;表达式的值是 package 所引用的对象的 name 属性的值。packageadd_package 方法的一个参数名称。当你 调用 这个方法时,你提供的值作为参数与名称 package 绑定。

例如,

  1. class Package:
  2. def __init__(self, name):
  3. self.name = name
  4. p = Package("foo") # p.name == "foo"
  5. r = Repository()
  6. r.add_package(p) # self.packages["foo"] = p
英文:

package.name is an expression; the value of the expression is the value of the name attribute of whatever object package refers to. package is the name of a parameter of the add_package method. When you call this method, the value you provide as an argument is bound to the name package.

For example,

  1. class Package:
  2. def __init__(self, name):
  3. self.name = name
  4. p = Package("foo") # p.name == "foo"
  5. r = Respository()
  6. r.add_package(p) # self.packages["foo"] = p

huangapple
  • 本文由 发表于 2023年3月4日 03:16:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631055.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定