Skip to main content

Instant Hacking: The Basics

  • Chapter
  • First Online:
  • 20k Accesses

Abstract

It’s time to start hacking. In this chapter, you learn how to take control of your computer by speaking a language it understands: Python. Nothing here is particularly difficult, so if you know the basic principles of how your computer works, you should be able to follow the examples and try them out yourself. I’ll go through the basics, starting with the excruciatingly simple, but because Python is such a powerful language, you’ll soon be able to do pretty advanced things.

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

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   54.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   69.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

Learn about institutional subscriptions

Notes

  1. 1.

    Hacking is not the same as cracking, which is a term describing computer crime. The two are often confused, and the usage is gradually changing. Hacking, as I’m using it here, basically means “having fun while programming.”

  2. 2.

    After all, no one expects the Spanish Inquisition . . .

  3. 3.

    The slightly less simple story is that the rules for identifier names are in part based on the Unicode standard, as documented in the Python Language Reference at https://docs.python.org/3/reference/lexical_analysis.html .

  4. 4.

    In case you’re wondering—yes, it does do something. It calculates the product of 2 and 2. However, the result isn’t kept anywhere or shown to the user; it has no side effects, beyond the calculation itself.

  5. 5.

    Note the quotes around storage. Values aren’t stored in variables—they’re stored in some murky depths of computer memory and are referred to by variables. As will become abundantly clear as you read on, more than one variable can refer to the same value.

  6. 6.

    Function calls can also be used as statements if you simply ignore the return value.

  7. 7.

    If you don’t understand this sentence, you should perhaps skip the section. You don’t really need it.

  8. 8.

    This behavior depends on your operating system and the installed Python interpreter. If you’ve saved the file using IDLE in macOS, for example, double-clicking the file will simply open it in the IDLE code editor.

  9. 9.

    Actually, str is a class, just like int. repr, however, is a function.

  10. 10.

    Raw strings can be especially useful when writing regular expressions. You learn more about those in Chapter 10.

  11. 11.

    This is an important method of compression in general, used for example in Huffman coding, a component of several modern compression tools.

  12. 12.

    See https://docs.python.org/3/howto/unicode.html .

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Magnus Lie Hetland

About this chapter

Cite this chapter

Hetland, M.L. (2017). Instant Hacking: The Basics. In: Beginning Python. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0028-5_1

Download citation

Publish with us

Policies and ethics