Concepts and Vocabulary Flashcards

1
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

OPERATING SYSTEMS

• What is an operating system?
• What does an operating system do?
• How does Python interact with the operating system?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

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!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

IDES

• What is an IDE?
• What are some typical features of IDEs?
• What IDEs are best for Python?

A

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.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

COMMENTS

• What are comments?
• Why are comments useful in programming?
• What kinds of comments should you write?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

PROJECT SPECIFICATIONS

• What is a project specification?
• Why are specifications important?
• Who writes project specifications?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

SYNTAX

• What is syntax?
• What is a syntax error?
• What is a logical error?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

DEBUGGING

• What is a bug?
• What does debugging mean?
• How do you debug a program?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

REFACTORING

• What is refactoring?
• When and why should you refactor code?
• What is the DRY principle?
• How do you refactor code?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

STANDARD LIBRARY

• What is a standard library?
• What is usually included in a standard library?
• What is not included in a standard library?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

FRAMEWORKS

• What is a framework?
• What kinds of frameworks are available for Python?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

ERROR HANDLING

• Why is error handling important?
• How do you handle errors in a program?
• What is an exception?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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?

A

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.

17
Q

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

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.

18
Q

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?

A

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.

19
Q

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

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.

20
Q

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?

A

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.

21
Q

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?

A

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.

22
Q

STRINGS

• What is a string?
• Why are strings important?
• What is a substring?
• What can you do with strings?

A

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.
23
Q

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?

A

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.
24
Q

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

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.
25
Q

MAPPINGS

• What is a mapping?
• Why are mappings important?
• What can you do with a mapping?
• What is the main mapping type in Python?

A

A mapping is a data structure that connects two or more pieces of information, commonly called a key-value pair. When you ask for a key, you get its associated value. One mapping structure can store many key-value pairs.

Mappings don't just store data. They allow you to establish relationships between the data. For example, you could pair each username with a password, each country with its capital, and each book with its author.

Mappings are not limited to single pieces of data: you could use a single piece of data as a key and use a sequence as the value. For example, you could pair a username with a sequence of other users to define a relationship between one user and other users. This is the core of how many social networks are implemented.

In Python, the dictionary is the main mapping type. Make sure you understand dictionaries, because many advanced Python data structures are represented internally by dictionaries.
26
Q

FUNCTIONS

• What is a function?
• What are parameters and arguments?
• What is a function call?
• What are functions used for?

A

A function is a block of code that you can name and that performs a certain task. You can run the block many times by using the function name. The definition of a function specifies its name and the data the function needs to work. Parameters are the variables in the function that hold this data.

To use a function, you call it. When you call a function, you must provide values, or arguments, for each of the function's parameters. 

Functions allow you to write code efficiently. When you need to perform an action more than once, wrap that code in a function and call it when you need it. When you need to change how the action is carried out, you can change the code in the function, and the improvement is applied everywhere.
27
Q

CLASSES

• What is a class?
• What are attributes and methods?
• What is an instance?
• What can you do with a class?

A

A class is a structure that allows you to combine the data and functionality associated with a particular task. The variables of a class are attributes.
The functions of a class are methods.

Classes can represent real-world objects or abstract ideas. After defining a class, you use it by making an instance, or object, of the class. You can make as many instances as you want from one class.

As an example, you might use a class to represent a website user. The class would have attributes associated with the user's username, password, registration date, and more. Methods would define the actions the user could take, such as registering, authenticating, logging in, and logging out. You could then make one instance for each user who registers on the site.

Many external libraries are written as classes, so learning to work with classes makes it easier to work with many existing projects.
28
Q

INHERITANCE

• What is inheritance?
• What is a parent class?
• What is a child class?

A

Inheritance is the idea of basing one class on another class so the new class can use the existing methods and attributes. When your classes are modeled on similar things, use inheritance rather than starting a new class.

Imagine you want to model a book, so you write a class called Book. The class attributes might be author, title, and subject, and methods might be describe_book(), show_sample_page(), and review_book(). An ebook is a kind of book, so you could make EBook inherit from Book so it has all the attributes and methods of Book. Then you only need to define any additional attributes and methods specific to ebooks, such as a file_size attribute and a download_book() method.

In this example, Book is a parent class and EBook is a child class. A child class inherits from the parent class. When you write a child class, you can add any attributes or methods not in the parent class, as well as customize the behaviors inherited from the parent class.
29
Q

OTHER DATA TYPES

• What is a Boolean value?
• What are Boolean values used for?
• What is a null value?
• What are null values used for?

A

A Boolean value represents either true or false. In Python, these values are written as True and False.

Boolean values can represent the state of a program or a certain condition. For example, you can use variables such as game_active, can _edit, and polling_open, which take either a True or False value. When these values are True, certain code sections are enabled as the program runs.

A null value represents nothing. You would assign a null value to a variable that doesn’t have a defined value. In Python, this is written as None. In logical comparisons, None evaluates to False.

The null value is useful in a many situations. For example, you can use it to make some parameters for a function optional. If a value is provided, the parameter is assigned the given value. If no value is provided, the parameter doesn't have any effect on the program. A function can also return None when it can't do its work, instead of generating an error that might cause the program to crash.
30
Q

IF STATEMENTS

• What is an if statement?
• What are if statements used for?
• What is an elif statement?
• What is an else statement?

A

An if statement allows you to set a condition on whether certain code runs. For example, using a variable called game _active, you can use an if statement to ensure the code that starts a game runs only if this variable is set to True.

An if statement allows programmers to respond to user input, and it changes conditions during a program's execution.

You can use the elif, or else if, statement to make your program respond to multiple conditions. This code structure means "if one condition applies, do this; else if a different condition applies, do something different." You can chain together as many of these specific conditions as you need.

An else block runs a particular block of code when all other conditions don't apply. An else block must always be the last block in an if-elif-else chain.
31
Q

LOOPS

• What is a loop?
• What are loops used for?
• What is a for loop?
• What is a while loop?
• What is a nested loop?

A

A loop is a block of code that runs multiple times. Use loops when you need to repeat actions more than once, depending on certain criteria. The two loop types are the for loop and the while loop.

A for loop repeats as many times as you specity or once for each item in a sequence. For example, you can write a for loop that runs 100 times to repeat an action 100 times. You can also write a for loop that runs once for each item in a collection of items.

A while loop runs as long as a certain condition is true. Say you have a game loop that runs as long as a game_active variable is set to True. You can then put multiple situations inside the loop that cause game_active to become False and end the game. You can also use a while loop to process items in a collection that might have new items added to it as the loop is running. As long as items are in the collection, you can keep working with it. When the collection is empty, the loop stops running. 

A nested loop is a loop inside another loop. Say you need a loop that examines every pixel in an image. You could write a loop that looks at each pixel in a row and, inside that loop, add a second loop that looks at every pixel in the current column for that row.
32
Q

MODULES

• What is a module?
• Why are modules important?
• How do you use a module in a program?

A

In Python, a module is a file that contains code. Modules are used to break up large programs into smaller parts for more manageable coding.

Modules compartmentalize complex programs. Programmers break up larger projects into different files, each of which focuses on one aspect of the project. This makes large projects easier to write and collaborate on in teams: each programmer can focus on only the modules they're responsible for.

To create a module, you move code that has a particular aim into a separate file. To use a module, import it into the file you're working on to make the code available. You can import the entire module or just the parts you need.
33
Q

SAVING STATE

• What is a program’s state?
• What is the JSON format?
• Why is JSON used to save state?

A

The state of a program is the set of values of all the variables at a given moment. Saving state refers to saving these values so they can be recovered if the program crashes or the user closes it.

A common way to save a program's state is to write the current values to a JSON file. JSON (JavaScript Object Notation) is a way of storing data that's easy for programs to read back. Originally developed for use in JavaScript programs, JSON is now used by many programming languages.

The JSON format can be read by programs and by humans. Some simple JSON data files look just like Python code. Python has libraries you can use to simplify reading and writing JSON files.