Abstract
But most of the time we're actually most interested in the objects we create. By the end of this chapter, you will be able to add objects into your game to represent weapons.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
In a real application, we would of course use Python’s date and time library to calculate the year born, but this will serve for our demo.
- 2.
In fact, self is not a reserved keyword, but it is a convention that everyone follows.
- 3.
The method that is searched for is called __repr__(). We’re sticking with __str__() here because the purpose of __str__() is to make objects readable. The purpose of __repr__() is to aid in troubleshooting when something goes wrong in an application. In real applications, you may want to also implement __repr__(), but it’s beyond the scope of our game.
- 4.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2018 Phillip Johnson
About this chapter
Cite this chapter
Johnson, P. (2018). Objects. In: Make Your Own Python Text Adventure. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3231-6_8
Download citation
DOI: https://doi.org/10.1007/978-1-4842-3231-6_8
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-3230-9
Online ISBN: 978-1-4842-3231-6
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)