本文整理汇总了Python中Person.Person.name方法的典型用法代码示例。如果您正苦于以下问题:Python Person.name方法的具体用法?Python Person.name怎么用?Python Person.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person.Person
的用法示例。
在下文中一共展示了Person.name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mutator
# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import name [as 别名]
#!/usr/bin/env python
from Person import Person # include Person.py
# initialize data through mutator (set)
captain = Person() # instantiate new object
captain.name = "Jean-Luc" # instance var via direct access
# access and print data through accessor (get)
name = captain.name # instance var via direct access
print "Name of the Person:\n\t" + name
示例2: print
# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import name [as 别名]
#!/usr/bin/env python
from Person import Person # include Person.py
print("Creating two objects:\n")
# create two objects
captain = Person() # instantiate new object
officer = Person() # instantiate new object
# initialize data through mutator (set)
captain.name = "Jean-Luc" # call mutator
officer.name = "Data" # call mutator
print("\nPrinting Results:\n")
# retrieve string from captain object through accessor (get)
name = captain.name # call accessor
# output results
print(" Name of the Captain:\n\t" + name)
# retrieve string from officer object through accessor (get)
name = officer.name # call accessor
# output results
print(" Name of the Officer:\n\t" + name)
print("")