当前位置: 首页>>代码示例>>Python>>正文


Python Person.name方法代码示例

本文整理汇总了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
开发者ID:darkn3rd,项目名称:oop-tut,代码行数:12,代码来源:demo.py

示例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("")
开发者ID:darkn3rd,项目名称:oop-tut,代码行数:29,代码来源:demo.py


注:本文中的Person.Person.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。