Skip to main content

Objects

  • Chapter
  • First Online:
Make Your Own Python Text Adventure
  • 4593 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 29.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 37.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 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. 2.

    In fact, self is not a reserved keyword, but it is a convention that everyone follows.

  3. 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. 4.

    https://docs.python.org/3.5/library/string.html#formatspec

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Phillip Johnson

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

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

Publish with us

Policies and ethics