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


Python Person.setName方法代码示例

本文整理汇总了Python中Person.Person.setName方法的典型用法代码示例。如果您正苦于以下问题:Python Person.setName方法的具体用法?Python Person.setName怎么用?Python Person.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Person.Person的用法示例。


在下文中一共展示了Person.setName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inheritance_two

# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setName [as 别名]
def inheritance_two():
    car = {}

    driver = Passenger()
    driver.setName('Bob')
    driver.setAge(30)
    driver.setSeatPosition(0)
    driver.setIsDriver(True)

    passenger = Passenger()
    passenger.setName('Jim')
    passenger.setAge(40)
    passenger.setSeatPosition(1)

    person = Person()
    person.setName('Jack')
    person.setAge(25)

    car['driver'] = driver
    car['passenger'] = passenger
    car['otherpassenger'] = person

    for key in car:
        occupant = car[key]
        try:
            print('Occupant ' + occupant.getName() + (', driving' if occupant.getIsDriver() else ', passenger' ) )
        except AttributeError as ae:
            if isinstance(occupant, Human):
                print('Occupant ' + occupant.getName() )
            else:
                print( 'Error : ' + ae.message)
开发者ID:rikkouri,项目名称:project-a,代码行数:33,代码来源:Inheritance.py

示例2: Person

# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setName [as 别名]
# 1_Class_and_Object

from Person import Person

person = Person()

person.setName("John")
person.setAge(25)

person.descriptionOfPerson()
开发者ID:l2sega,项目名称:OOP,代码行数:12,代码来源:Main.py

示例3: Person

# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setName [as 别名]
from Person import Person

print 'Welcome to the community'

mom = Person()
dad = Person()
child1 = Person()
child2 = Person()

mom.setName('Adele')
mom.setAge(25)
dad.setName('Ryan')
dad.setAge(28)
child1.setName('Jaxon')
child1.setAge(3)
child2.setName('Tiberius')
child2.setAge(0)

mom.outputPerson()
dad.outputPerson()
child1.outputPerson()
child2.outputPerson()
	

开发者ID:anthony2445,项目名称:csci-3070u,代码行数:24,代码来源:Community.py

示例4: Person

# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setName [as 别名]
#!/usr/bin/env python3
# persons.py - Person program
from Person import Person

person1 = Person("Bob", 28)
person2 = Person("Jack", 42)
person3 = Person("Mary", 38)
person4 = Person()
person4.setName("Jim")
person4.setAge(35)

print("There are %d people" %Person.numPersons())

for person in (person1, person2, person3, person4):
    print(person)

# delete all persons ...your code here...
print("There are %d people" %Person.numPersons())

#################################################
#
#    $ persons.py
#    There are 4 people
#    Name: Bob Age: 28
#    Name: Jack Age: 42
#    Name: Mary Age: 38
#    Name: Jim Age: 35
#    There are 0 people
#
开发者ID:tamle022276,项目名称:python,代码行数:31,代码来源:persons.py

示例5: Passenger

# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setName [as 别名]
# Create the driver and passenger, both instances of Passenger
driver = Passenger()
driver.setName('Paul')
driver.setAge(43)
driver.setIsDriver(True)
driver.setSeatPosition(0)

passenger = Passenger()
passenger.setName('Bob')
passenger.setAge(23)
passenger.setIsDriver(False)
passenger.setSeatPosition(1)

# Create a Person object
person = Person()
person.setName('Charlie')
person.setAge(35)

# Add both our passengers
mycar.addOccupant(driver)
mycar.addOccupant(passenger)

# And then our person. The addOccupant method does not specify an object type.
# We could add some handling inside the Car class to raise an error if
# the occupant to be added does not match an expected type.
mycar.addOccupant(person)

print( 'The ' + mycar.getMake() + ' ' + mycar.getModel() + ' is transporting ')
for occupant in mycar.getOccupants():
    # We'll hit an (unhandled) exception here when we try to call a nonexistent method on the Person object
    print(occupant.getName() + (', driving' if occupant.getIsDriver() else ', passenger'))
开发者ID:rikkouri,项目名称:project-a,代码行数:33,代码来源:Polymorphism.py


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