Concepts and Vocabulary Flashcards
(33 cards)
PROGRAMMING LANGUAGES
• What is a programming language?
• What’s unique about Python?
• How does a programming language affect the way we think about solving problems?
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.
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 characteristic programming styles and philosophies. Python focuses on simplicity, readability, and getting the job done.
OPERATING SYSTEMS
• What is an operating system?
• What does an operating system do?
• How does Python interact with the operating system?
The operating system (OS) is the software that controls the computer’s inner workings.
An operating system performs low-level functionality, such as reading from and writing to memory, and interacts with hardware devices, like hard drives, RAM, CPUs, GPUs, dis-plays, 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.
TERMINAL
• What is a terminal?
• How do you run a Python program from a terminal?
• How do you start a Python session from a terminal?
A terminal is a program that allows you to interact with the OS, and it is often referred to as the console 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.
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!
TEXT EDITORS
• What is a text editor?
• What is syntax highlighting?
• What are some beginner-friendly text editors?
• What are some more advanced text editors?
A text editor is a program designed for writing and editing code.
Most text editors have features to make writing and editing 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.
VS Code, Sublime Text, and Geany are some commonly used beginner-friendly text editors because of their ease of use and familiar interfaces. They also have powerful tea-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.
IDES
• What is an IDE?
• What are some typical features of IDEs?
• What IDEs are best for Python?
An integrated development environment (IDE) is a text editor with powerful project management features.
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 consistency across the project.
IDEs can make code testing easier and identity 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 and VS Code. (VS Code can behave like a simple text editor, but it also has many features commonly associated with IDEs.)
COMMENTS
• What are comments?
• Why are comments useful in programming?
• What kinds of comments should you write?
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.
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 ettectively.
STYLE GUIDES
• What is a style guide?
• What kinds of recommendations are made in style guides?
• Where can you find the Python style guide?
A style guide offers direction on creating consistency in your code, such as how far you indent lines, your maximum line length, or how you break lengthy lines.
A style guide is not a set of rules: if you break the guidelines but follow the syntax rules, your code will still run. When you follow a style guide, your code will be consistent, 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.
PROJECT SPECIFICATIONS
• What is a project specification?
• Why are specifications important?
• Who writes project specifications?
A project specification, or spec, lists requirements for what a program needs to do.
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.
SYNTAX
• What is syntax?
• What is a syntax error?
• What is a logical error?
The syntax of a programming language is the set of rules for how to write instructions in that language; syntax is like the grammar for that lan-guage. The syntax rules tell you how to store data, respond to specific conditions, and control the flow of execution in the language.
A syntax error occurs when a program doesn’t follow the syntax rules. The language won’t understand how to execute the code, even if only a minor mistake is made, such as a missing parenthesis or comma.
A logical error occurs when your program follows the syntax rules and runs, but doesn’t do what you want it to do. You’ll know you have a logical error when your project generates output but the output doesn’t match the project spec. You’ll need to reevaluate your approach to the problem and then modify that approach.
DEBUGGING
• What is a bug?
• What does debugging mean?
• How do you debug a program?
A bug is a problem in the way a program runs. Debugging is the process of identifying the cause of a bug and modifying code to fix the issue.
One of the first steps in debugging is to understand error messages. They tell you where the interpreter had a problem and what kind of problem occurred.
Logical errors don’t result in error messages, so you need to look at the program execution to resolve them. To debug logical errors, examine the value of variables at different points in the program’s execution. Do this by inserting print() calls into the code at strategic points, logging the values of key variables during execution, or using the debugging tools available in most IDEs. Also, write tests for your code to see which parts are working and which are not.
REFACTORING
• What is refactoring?
• When and why should you refactor code?
• What is the DRY principle?
• How do you refactor code?
Refactoring is the process of rewriting parts of a working program to make it simpler, more efficient, and easier to work with.
Consider refactoring code when you’ve solved the same problem in multiple places. This approach follows the don’t repeat yourself, or DRY, principle. Code repetition presents opportunities for errors, makes programs harder to modify, and makes programs longer and harder to read.
To refactor code, place a repeated block of code into a separate function. Then replace the repeated code with a function call. When you need to improve that code, you only need to change the code in the function for it to work throughout the program. Refactoring can help you find more efficient ways to solve problems, and separating code into different modules makes it easier to work with.
STANDARD LIBRARY
• What is a standard library?
• What is usually included in a standard library?
• What is not included in a standard library?
A standard library is the set of tools included in a language’s standard installation. The library includes core data structures and tools for working with data in your program.
Python’s standard library includes tools to help you:
• Work with a variety of data types and text
• Use mathematical functions
• Work with files and dates and times
• Make graphical user interfaces (GUls)
• Work with networks and multimedia
• Test and debug your code and handle errors
• Distribute your programs
Seldom does a standard library include specialized data analysis tools, game frameworks, web application frame-works, and other application-specific libraries. These are available through external libraries that are updated more often than the language as a whole.
Once you understand a language’s core syntax and rules, become familiar with the language’s standard library tools as these can help you write code efficiently.
THIRD-PARTY LIBRARIES
• What is a third-party library?
• What is a package?
• What is a package manager?
• What kinds of third-party libraries are available for Python?
A third-party library adds tools and functionality that aren’t covered by a language’s standard library.
Third-party libraries, or packages, are installed through an automated package manager, such as pip, for consistent and secure installation. A package manager also helps keep the libraries you’ve installed up-to-date.
More than 400,000 packages are available through the Python package manager. For example, the requests package helps you write programs to access online resources, Pillow helps you work with images, SQLAlchemy makes it easier to work with databases, and NumPy offers tools for working with numerical data.
FRAMEWORKS
• What is a framework?
• What kinds of frameworks are available for Python?
A framework is a larger package that helps solve a particular problem. Some frameworks help you build games, data visualizations, and web applications.
A framework includes tools that handle common tasks within a problem area. For example, a game framework often provides a way to determine when a collision between two game elements has occurred. A web application framework usually provides a way to extract information from a database.
Simple frameworks leave it to you to make many problem-solving decisions; larger frameworks have more default approaches to common situations.
Popular Python web frameworks include Django, a large framework that provides tools to build web applications, and Flask, a bare-bones web application framework that leaves many decisions up to you. Popular game frameworks include Pygame, Kivy, and Pyglet.
ERROR HANDLING
• Why is error handling important?
• How do you handle errors in a program?
• What is an exception?
Error handling refers to writing code that anticipates errors that are likely to occur and then responds to those errors.
To run successfully, a program needs the correct set of inputs and the ability to do its work, and it must return its output appropriately. Errors can happen during any of these stages. Well-written programs have error-handling code that anticipates and deals with errors that might occur at each stage.
Error handling can just be code that checks certain values and conditions before proceeding. If the values and conditions are appropriate, execution continues along one path. If not, it follows a different path.
One common approach is to check whether input is in the correct format. When a user inputs their age, you expect a positive number. You can add code to check for a positive number before continuing and then raise an exception if anything else is entered. An exception is a special error condition that responds to a specific kind of error.
VERSION CONTROL
• What is version control?
• What is a commit?
• What does it mean to “check out” a commit?
• What is a repository?
• Why is version control important?
• What is distributed version control?
Version control is the process of saving different versions of your project as it evolves. If you break a program, you can return to a previously working version, or you can simply examine how your program worked in a previous version.
Version control systems work by allowing you to make a commit, which saves the current state of all the files in your project. You make a commit after implementing a new feature.
If you make a mistake and can’t figure out how to fix your program, you can check out the previous commit and start again from a working version of your project.
A repository is the collection of all commits you’ve made to a project; it contains other resources required to manage your project as well.
A distributed version control system allows multiple people to make commits on the same project and provides tools for resolving conflicts in collaborative projects.
Git is by far the most common version control system in use at the time of this writing.
TESTING
• What is a test?
• How do you write a test?
• What is an assertion?
• Why should you write tests for your code?
• How do tests help you add new features to a project?
A test is code outside your program that runs some of your program code to check whether it works correctly.
Each part of a program solves one aspect of a larger problem your program aims to solve. You can write tests that prove each part of your code behaves properly.
To write a test, you import the code you want to test, set up sample data, and run the code using that data. Then you can make assertions about the results.
An assertion is a statement about what a value or condition should be. For example, you might assert that the value of the variable age is greater than 18. If the code acts as it should, the test passes. It it doesn’t, the test fails.
A good set of tests helps you find bugs before your users do. It also helps ensure that when you add new features to your projects, the code doesn’t affect the behavior of existing features and your program still works.
USER INTERFACES
• What is an application programming interface?
• What is a graphical user interface?
• What is a command line interface?
• Why is each of these important?
An application programming interface (API) is a specification for how one program asks another program for information. A graphical user interface (GUI) is an easy-to-use interface that lets users click elements on the screen. A command line interface (CLI) allows users to interact with a program by entering commands in a terminal.
Using a GUl is the simplest way for nontechnical users to interact with a program. For example, a weather website would present information in a browser (a GUI) for general users, but it might also provide an API that technical users can work with to build projects that use real-time weather data.
APls allow you to pull in data from external resources. Developers working on large, collaborative projects can build their own APls to design how each program in the project communicates. Designing and building a good API requires experience and planning, but learning to use an API is much simpler.
A CLI enables automation and scripting in a more customizable fashion than with GUls.
DATABASES
• What is a database?
• Why are databases important?
• What is SQL?
• How do you communicate with a database?
• What are some common databases?
A database is a program that allows you to store and retrieve information. Good databases are highly optimized to do this efficiently and reliably with large amounts of data.
Databases store most of the world’s information. Whenever you retrieve information from a website or post to a website, that information is being read from or written to a database. Many of the projects programmers work on interact with a database.
Structured Query Language (SQL) is a language written specifically to interact with databases, but you don’t need to know SQL to work with a database. Many languages and frameworks generate SQL for you, so you can work with the database through those languages. If you’re serious about programming, however, it’s a good idea to learn SQL.
SQLite, PostgreSQL, MySQL, SQL Server, and Oracle are the most common databases used in programming.
DATA STRUCTURES AND TYPES
• What are data structures?
• What are data types?
• Why are data structures important?
• What are the most common kinds of data structures?
Data structures define how you store data in a programming language. Every programming language has a core set of data structures. Data types refer to the data structures you’re using or the kind of information stored in those data structures.
Much of programming focuses on handling data. How you represent data through code impacts what you can do with that data: if you model your data well, your program is easier to work with.
Choosing a specific approach to data modeling informs how you think about data, so knowing the available data structures in a programming language will help you best represent the information in your project.
The most common data structures include variables, sequences, mappings, classes, and objects. Python also has text-based data types, such as strings, and numerical data types, such as integers and floats.
VARIABLES
• What is a variable?
• Why are variables important?
• What is a statically typed language?
• What is a dynamically typed language?
• What makes Python a dynamic language?
In Python, a variable is a name attached to a piece of data. You first define a variable, then use that name when you refer to that piece of data.
In statically typed languages, you must declare the kind of data a variable represents when you define it. Python is a dynamically typed language, meaning you don’t have to declare the kind of data a variable will represent. In Python, the interpreter examines the data associated with the variable throughout the life of the program and manages type issues for you.
Dynamic languages prioritize a programmer’s time over efficient use of the processor, but they can still be fast and efficient when used properly. Static languages prioritize processor efficiency over a programmer’s time. Programs are longer and more verbose in static languages, but can be highly optimized.
STRINGS
• What is a string?
• Why are strings important?
• What is a substring?
• What can you do with strings?
A string is a value made up of text. A classic example of a string is the code “Hello, world!”
A string is one of the simplest data types in any lan-guage. Much of the information that's passed within and between programs is strings. Strings are treated as a collection of characters, so the string "123" is different from the numerical value 123. A substring is part of a string. You can perform many actions with strings:
• Joining strings together, known as concatenation
• Inserting the value of a variable into a string, known as interpolation
• Changing a string’s case
• Stripping extra whitespace from a string
• Searching for a substring within a string
• Replacing some characters in a string
In Python, strings are enclosed using single or double quotes.
NUMERICAL DATA TYPES
• What is an int?
• What is a float?
• What can you do with numerical data?
• What other kinds of numerical data types are available?
Integers and floats are the two main kinds of numerical data types. An integer, or int, is a number with no decimal part. A float is a number with a decimal part.
You can perform all basic arithmetic operations with numerical data and do higher-order operations, such as working with exponents, finding absolute values, and working with trigonometric functions. Python allows you to represent complex numbers (num-bers with real and imaginary parts) and work with fractions. For computation-intensive work, third-party libraries, such as NumPy, SciPy, and pandas, can make your work easier. Many dedicated visualization libraries are available as well, such as Matplotlib, Bokeh, Seaborn, and Plotly.
SEQUENCES
• What is a sequence?
• Why are sequences important?
• What kinds of things can you do with a sequence?
• What kind of sequences are available in
Python?
• What is a mutable sequence?
A sequence is a data structure that stores a collection of items in a specific order. In some languages, a sequence can only contain items of one type; in other languages, including Python, a sequence can have items of different types.
Sequences are important when you need to store items in a specific order. For example, a list of website users might be ordered according to when each user registered. With a sequence, you can do the following:
• Add and remove items
• Work with individual items or groups of items
• Determine whether a value is in the sequence
• Look for duplicate or unique items
• Loop through the sequence and do something with each item
• Work with items that match certain conditions.
In Python, the main sequence type is the list. Lists are mutable, meaning you can modify them after creating them. Tuples are immutable sequences, meaning they can't be changed after they're defined. Strings are a special type of sequence: each element in the sequence is a character.