E R I C M A T T H E S 101 C A R D S PY T HON F L A SH C A R DS From the best-selling author of Python Crash Course
These cards introduce a variety of important programming concepts. Understanding these concepts will help you make sense of the relevant syntax when you get to it, in Python or any other language you choose to study. You can read these cards as a set before moving on to the syntax cards, or you might visit relevant concepts here as you work on individual topics from the syntax cards. ConCep t s a nd VoCa bul a ry 1 Co n C e p t s a n d Vo C a bu l a ry
1.1 Programming Languages 1.2 Operating Systems 1.3 Terminal 1.4 Text Editors 1.5 IDEs 1.6 Comments 1.7 Style Guides 1.8 Project Specifications 1.9 Syntax 1.10 Debugging 1.11 Refactoring 1.12 Standard Library 1.13 Third-Party Libraries 1.14 Frameworks 1.15 Error Handling 1.16 Version Control 1.17 Testing 1.18 User Interfaces 1.19 Databases 1.20 Data Structures and Types 1.21 Variables 1.22 Strings 1.23 Numerical Data Types 1.24 Sequences 1.25 Mappings 1.26 Functions 1.27 Classes 1.28 Inheritance 1.29 Other Data Types 1.30 if Statements 1.31 Loops 1.32 Modules 1.33 Saving State
progr a mming l a nguages • What is a programming language? • What’s unique about Python? • How does a programming language affect the way we think about solving problems? 1.1
Python is a high-level programming language, which means it takes care of many low-level tasks for you so you can focus on solving problems. For example, when you assign a value to a variable, Python deletes the variable automatically when it’s no longer needed, sparing you from having to manage memory. Every language has unique features that lead to charac- teristic programming styles and philosophies. Python focuses on simplicity, readability, and getting the job done. A programming language is a set of rules for giving instructions to a computer. It provides the syntax for giving instructions and specifies the ways to store information, and it controls the order in which instructions are executed in a program.
oper ating systems • What is an operating system? • What does an operating system do? • How does Python interact with the operating system? 1.2
An operating system performs low-level functionality, such as reading from and writing to memory, and interacts with hardware devices, like hard drives, RAM, CPU, graphics processors, displays, batteries, and other external devices. Windows, macOS, and Linux (such as Ubuntu and Fedora) are major operating systems. Python is a cross-platform programming language. You can write Python code on any OS, and it will run on any other OS. The operating system (OS) is the software that con- trols the computer’s inner workings.
termin a l • What is a terminal? • How do you run a Python program from a terminal? • How do you start a Python session from a terminal? 1.3
You can run a Python program from a terminal using a command like this: $ python hello_world.py You can also start a Python session in a terminal. In a Python terminal session, each line of code executes as soon as you enter it: $ python >>> print("Hello, terminal world!") Hello, terminal world! A terminal is a program that allows you to interact with the OS, and it is often referred to as the con- sole or command line. You use a terminal (rather than going through a GUI) to issue clear, concise, text-based commands to the OS to quickly perform tasks.
te x t editors • What is a text editor? • What is syntax highlighting? • What are some beginner-friendly text editors? • What are some more advanced text editors? 1.4
Most text editors have features to make writing and edit- ing code easier: syntax highlighting, for example, colors your code so you can quickly recognize different parts of a program—a string might be green and a method might be purple. Sublime Text, Atom, and Geany are some commonly used beginner-friendly text editors because of their ease of use and familiar interfaces. They also have powerful fea- tures that help you work more efficiently as you learn. Emacs and Vim are advanced text editors that were introduced in the 1970s. Their learning curve is steep, but once you learn to use them well, writing and editing code is incredibly efficient. Most Linux systems install Vim, or its predecessor vi, by default. A text editor is a program designed for writing and editing code.
ide s • What is an IDE? • What are some typical features of IDEs? • What IDEs are best for Python? 1.5
Typical IDE features include debugging tools, auto-filling for certain code elements, and the ability to catch errors as you’re entering code. For projects that span multiple files, the IDE looks through the files and helps maintain consis- tency across the project. IDEs can make code testing easier and identify portions of your code that you could refactor. IDEs help you interact with other project elements, such as HTML and JavaScript in a web application, and help you work with a database. Popular Python IDEs include PyCharm, PyDev, Spyder, and Visual Studio. An integrated development environment (IDE) is a text editor with powerful project management features.
Comment s • What are comments? • Why are comments useful in programming? • What kinds of comments should you write? 1.6
Use comments to explain: • The role of important variables when you introduce them • How you’ve approached a problem after considering multiple approaches • What your functions do • What classes are used for in the program Writing comments will remind you what your code does when you return to it later. Comments also help teams of programmers collaborate effectively. Comments are lines in a program that the program ignores when it executes. They allow you to add notes about how the program works to help you and other developers understand the code.
st y le guides • What is a style guide? • What kinds of recommendations are made in style guides? • Where can you find the Python style guide? 1.7
A style guide is not a set of rules: if you break the guide- lines but follow the syntax rules, your code will still run. When you follow a style guide, your code will be consis- tent, and it’ll be easier for you and others to focus on what it does rather than what it looks like. Python’s design ensures that programmers write more readable code with it than with other languages. Be sure to read the Python style guide, PEP 8, for suggestions on how to create clean and consistent code. A style guide offers direction on creating consis- tency in your code, such as how far you indent lines, your maximum line length, or how you break lengthy lines.
projeC t speCifiCations • What is a project specification? • Why are specifications important? • Who writes project specifications? 1.8
A clear specification is important in projects of all sizes so you have a solid idea of what to aim toward and whether your project is successful. Without a clear spec, you’ll waste time and risk your project’s failure. A project specification indicates the problems that need solving and how users will interact with the program. It should specify what kinds of inputs your program will deal with, as well as the outputs the program needs to generate. When learning to program, each exercise you attempt is a mini spec. Well-specified problems are easier to solve than poorly specified exercises. A good programmer looks for a spec when collaborating on an existing project and develops a full spec before committing to a new project. A project specification, or spec, lists requirements for what a program needs to do.
sy nta x • What is syntax? • What is a syntax error? • What is a logical error? 1.9
Comments 0
Loading comments...
Reply to Comment
Edit Comment