英文:
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?
class Repository:
def __init__(self):
self.packages = {}
def add_package(self, package):
self.packages[package.name] = package
答案1
得分: 1
package.name
是一个 表达式;表达式的值是 package
所引用的对象的 name
属性的值。package
是 add_package
方法的一个参数名称。当你 调用 这个方法时,你提供的值作为参数与名称 package
绑定。
例如,
class Package:
def __init__(self, name):
self.name = name
p = Package("foo") # p.name == "foo"
r = Repository()
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,
class Package:
def __init__(self, name):
self.name = name
p = Package("foo") # p.name == "foo"
r = Respository()
r.add_package(p) # self.packages["foo"] = p
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论