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
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 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.
After all, no one expects the Spanish Inquisition . . .
- 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.
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.
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.
Function calls can also be used as statements if you simply ignore the return value.
- 7.
If you don’t understand this sentence, you should perhaps skip the section. You don’t really need it.
- 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.
Actually, str is a class, just like int. repr, however, is a function.
- 10.
Raw strings can be especially useful when writing regular expressions. You learn more about those in Chapter 10.
- 11.
This is an important method of compression in general, used for example in Huffman coding, a component of several modern compression tools.
- 12.
Author information
Authors and Affiliations
Rights 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
DOI: https://doi.org/10.1007/978-1-4842-0028-5_1
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-0029-2
Online ISBN: 978-1-4842-0028-5
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)