0% found this document useful (0 votes)
56 views14 pages

Python Flashcards From PDF

Uploaded by

beniman11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views14 pages

Python Flashcards From PDF

Uploaded by

beniman11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

What is a programming language?

What™s unique about Python?


How does a programming language affect
the way we think about solving problems?
What is an operating system?
What does an operating system do?
How does Python interact with the operating
system?
What is a terminal?
How do you run a Python program from a
terminal?
How do you start a Python session from a

terminal?
What is a text editor?
What is syntax highlighting?
What are some beginner-friendly text editors?
What are some more advanced text editors?
What is an IDE?
What are some typical features of IDEs?
What IDEs are best for Python?
What are comments?
Why are comments useful in programming?
What kinds of comments should you write?
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.

S
TYLE
G
UIDES
What is a style guide?
What kinds of recommendations are made in
style guides?
Where can you ˜nd the Python style guide?
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
i t 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.

P
ROJE
C
T
S
PE
C
IFI
C
AT IONS
What is a project speci˜cation?
Why are speci˜cations important?
Who writes project speci˜cations?
When learning to program, each exercise you attempt
is a mini spec. Well-speci˜ed problems are easier to solve
than poorly speci˜ed 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 speci˜cation
, or spec, lists requirements
for what a program needs to do.

S
YN TAX
What is syntax?
What is a syntax error?
What is a logical error?
What is a bug?
What does debugging mean?
How do you debug a program?
What is refactoring?
When and why should you refactor code?
What is the DRY principle?
How do you refactor code?
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 ˜nd more
ef˜cient ways to solve problems, and separating code into
different modules makes it easier to work with.
Refactoring
is the process of rewriting parts of a
working program to make it simpler, more ef˜
-
cient, and easier to work with.

S
TANDARD
L
IBR ARY
What is a standard library?
What is usually included in a standard
library?
What is not included in a standard library?
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?
What is a framework?
What kinds of frameworks are available for
Python?
Why is error handling important?
How do you handle errors in a program?
What is an exception?
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 excep
-
tion if anything else is entered. An
exception
is a special
error condition that responds to a speci˜c kind of error.
Error handling
refers to writing code that antic
-
ipates errors that are likely to occur and then
responds to those errors.

VERSION
CON T ROL
What is version control?
What is a commit?
What does it mean to ficheck outfl a commit?
What is a repository?
Why is version control important?
What is distributed version control?
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?
What is an application programming
interface?
What is a graphical user interface?
What is a command line interface?
Why is each of these important?
What is a database?
Why are databases important?
What is SQL?
How do you communicate with a database?
What are some common databases?
When
-
ever 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 inter
-
act with a database.
Structured Query Language (SQL)
is a language written
speci˜cally to interact with databases, but you don™t need t o
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.
A
database
is a program that allows you to store
and retrieve information. Good databases are
highly optimized to do this ef˜ciently and reliably
with large amounts of data.

D
ATA
S
TRU
C
TURES
AND
T
YPES
What are data structures?
What are data types?
Why are data structures important?
What are the most common kinds of data
structures?
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 speci˜c 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
h a s text-based data types, such as strings, and numerical
data types, such as integers and ˚oats.
Data structures
de˜ne how you store data in a
programming language. Every programming lan
-
guage 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.

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?
What is a string?
Why are strings important?
What is a substring?
What can you do with strings?
What is an int?
What is a ˚oat?
What can you do with numerical data?
What other kinds of numerical data types
are

available?
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?
What is a mapping?
Why are mappings important?
What can you do with a mapping?
What is the main mapping type in Python?
When you ask for a key, you get
its associated value. One mapping structure can
store many key-value pairs.

F
UN
C
T IONS
What is a function?
What are parameters and arguments?
What is a function call?
What are functions used for?
When you call a function,
you must provide values, or
arguments
, for each of the func
-
tion™s parameters.
Functions allow you to write code ef˜ciently. 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.
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
de˜nition
of a function speci˜es its name and the
data the function needs to work.
Parameters
are
the variables in the function that hold this data.

CLASSES
What is a class?
What are attributes and methods?
What is an instance?
What can you do with a class?
What is inheritance?
What is a parent class?
What is a child 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.
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.

O
T HER
D
ATA
T
YPES
What is a Boolean value?
What are Boolean values used for?
What is a null value?
What are null values used for?
When these values are
True
,
certain code sections are enabled as the program runs.
A
Boolean value
represents either true or false.
In Python, these values are written as
True
and
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.
A
null value
represents nothing. You would assign
a null value to a variable that doesn™t have a
de˜ned value. In Python, this is written as
None
.
In

logical comparisons,
None
evaluates to
False
.

IF
S
TATEMENT S
What is an
if
statement?
What are
if
statements used for?
What is an
elif
statement?
What is an
else
statement?
What is a loop?
What are loops used for?
What is a
for
loop?
What is a
while
loop?
What is a nested loop?
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.
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.

M
ODULES
What is a module?
Why are modules important?
How do you use a module in a program?
What is a program™s state?
What is the JSON format?
Why is JSON used to save state?
What is a variable?
What are the rules for naming a variable?
What is a string?
How do you store a string in a variable?
How do you include tabs and newlines in a
string?
What is a string method? To change the case of a string, use the methods
title() ,
How do you change the case of a string? To change the case of a string, use the
methods title() ,
How do you strip whitespace from a string? To change the case of a string, use
the methods title() ,
How do you insert the value from a variable
into a string? In Python 3.6 onward, you can use a variable directly inside a
string: >>>
How do you include a comment in
your

code? Comments begin with a hash mark: # Greet the user. username =
When should you include comments? Comments begin with a hash mark: # Greet the
user. username =
What are the two main types of
numerical

data? The type() function identi˜es the data type of its argument.
How do you ˜nd out what type of data

you™re

working with? The type() function identi˜es the data type of its argument.
How do you convert between the two

numerical types? The type() function identi˜es the data type of its argument.
How do you represent basic mathematical
operations? Using addition, subtraction, or multiplication with integers returns an
integer: >>>
How does the operation you™re using affect

the type of your output? Using addition, subtraction, or multiplication with


integers returns an integer: >>>
How do you force Python to use a

nonstandard order of operations? Using addition, subtraction, or multiplication


with integers returns an integer: >>>
How do you round numbers? The round() function rounds a ˚oat to the given
number
How do you get the absolute value of a
number? The round() function rounds a ˚oat to the given number
How do you convert a base-10 number to

binary, octal, or hexadecimal? The round() function rounds a ˚oat to the given
number
How do you represent complex numbers? The round() function rounds a ˚oat to the
given number
How do you take the square root of a
number? The math library provides a number of functions for opera
How do you use a mathematical constant

such as pi? The math library provides a number of functions for opera
How do you use trigonometric and

logarithmic functions? The math library provides a number of functions for opera
What is a list?
How do you de˜ne a list?
How do you add items to a list?
How do you remove an item from a list?
How do you remove an item at a certain
position from a list?
What is a slice?
How do you make a slice from the beginning
of a list?
How do you make a slice at the end of a list?
What can you do with a copy of a list?
How do you make a copy of a list?
What is a
for
loop?
How do you loop through a list?
How do you loop through a section of a list?
How do you sort a list temporarily?
How do you sort a list permanently?
How do you sort a list in reverse alphabetical
order?
How do you reverse a list™s order?
How do you make a simple list of numbers?
How do you make a list of numbers that
follows a speci˜c pattern?
What is a list comprehension?
How do you use a list comprehension?
What is a tuple?
How do you de˜ne a tuple?
How do you work with a tuple?
What is a dictionary?
How do you de˜ne a dictionary?
How do you get information out of a
dictionary?
What does the dictionary method
get()
do?
What does the method
keys()
do?
What does the method
values()
do?
What does the method
items()
do?
How do you loop through all the keys in a
dictionary?
How do you loop through all the values in a

dictionary?
How do you loop through all the key-value

pairs in a dictionary?
What does a dictionary of multiple similar
objects look like?
What does a dictionary that represents only

one object look like?


How do you store a set of dictionaries in
a
list?
How do you work with dictionaries stored in

a list?
How do you use a list inside a dictionary?
How do you work with a list that™s stored in a
dictionary?
What is a conditional statement?
What is a Boolean value?
What kinds of logical tests can you perform
in a conditional statement?
How do you write a simple
if
statement?
How do you write an
if
-
else
statement?
How do you write a series of
if
-
elif
-
else

statements?
How do you prompt the user for input?
How do you work with the data entered by
a

user?
What's your name?
What's your name?
How much for the truck?
How much for the truck?
What is a
while
loop?
How do you use a list with a
while
loop?
What does
break
do to a loop?
What does
continue
do to a loop?
What's your name? 5 5 is a great age!
What's your name? 5 5 is a great age!
What's your name? 5 5 is a great age!
How old are you? 5 5 is a great age!
How old are you? 5 5 is a great age!
How old are you? 5 5 is a great age!
How old are you? 5 5 is a great age!
What is a function?
How do you de˜ne functions?
How do you call functions?
What is a parameter?
What is an argument?
How do you write a function that takes in
information?
How do you pass arguments to functions?
What are positional arguments?
How do you use positional arguments in a
function call?
What happens if you use positional

arguments in the wrong order?


When a function needs more than one value, it
must match the values it receives to its parameters.
Using
positional
arguments, the function matches
the ˜rst value it receives to the ˜rst parameter,
and

so on.

ARBIT R
A
RY
POSIT ION
A
L
ARGUMEN T S
How do you write a function that accepts an
unknown number of arguments?
How do you call a function that accepts an

arbitrary number of arguments?


What are keyword arguments?
How do you use keyword arguments in a
function call?
How do you write a function that accepts an
arbitrary number of keyword arguments?
How do you call a function with an arbitrary

number of keyword arguments?


How do you assign a default value for a
parameter? 6 .11 Here we import from the
How do you call a function that has a default

value for a parameter? 6 .11 Here we import from the


What is a return value? 6 .11 Here we import from the
How do you write a function that returns a
value? 6 .11 Here we import from the
When the function is called, the return value is stored in
the variable
my_area
. Here™s the output:
20
You can return any kind of value. To return more than
one value, place the values in parentheses to return them as
a tuple.
A function sends a
return value
back to the line
that called the function, so the value can be used
later in the code. The calling line uses a variable to
store the return value.

M
ODULES
What is a module? 6 .11 Here we import from the
How do you create a module? 6 .11 Here we import from the
When you add to and improve
functions in modules, the changes are immediately avail
-
able to all programs that use them.
A
module
is a Python ˜le that contains multiple
functions or classes. By storing functions in this
separate ˜le, you can call them in programs with
-
out having to enter the full function code each time.

I
M
P
ORT ING
FUNC T IONS
How do you import an entire module and use
each of the functions in the module? 6 .11 Here we import from the
How do you give a module an alias when

importing it? 6 .11 Here we import from the


How do you import one function from a
module? 6 .11 Here we import from the
How do you import several individual

functions from a module? 6 .11 Here we import from the


What is a class? This class represents a trail, such as a hiking trail, with two
attributes, self.dest
What is an attribute? This class represents a trail, such as a hiking trail, with
two attributes, self.dest
What is a method? This class represents a trail, such as a hiking trail, with two
attributes, self.dest
How do you de˜ne a class? This class represents a trail, such as a hiking
trail, with two attributes, self.dest
How do you de˜ne a method? This method generates a description of a trail and
prints that description: class
How do you make an instance of a class? This method generates a description of a
trail and prints that description: class
How do you make an instance of a class? Here we make an instance of Trail and
call the method
How do you access the value of an attribute
through an instance? Here we make an instance of Trail and call the method
How do you use an instance to call methods? Here we make an instance of Trail
and call the method
How do you de˜ne a class with multiple
methods? Here™s Trail with a second method de˜ned:
How do you make multiple instances from
a
class? Here, the same class generates two trails: verst = Trail( "Mt.
Verstovia"
What is inheritance? This BikeTrail class modi˜es the behavior of the method
What is a parent class? This BikeTrail class modi˜es the behavior of the method
What is a child class? This BikeTrail class modi˜es the behavior of the method
How do you use inheritance? This BikeTrail class modi˜es the behavior of the
method
How do you write a new method for a child
class? This BikeTrail class modi˜es the behavior of the method
How does a child class modify the behavior
of a method from the parent class? This BikeTrail class modi˜es the behavior of
the method
How do you store a class in a module? Here we store the classes Trail and
How do you import a class from a module? Here we store the classes Trail and
How do you use an imported class? Here we store the classes Trail and
What is the
unittest
module?
How do you write a test case?
What does the
unittest.assertEqual()

method do?
What other assert methods are available?
How do you write a test for a function?
How do you run a test for a function?
What does a passing test look like?
When complete, the test case runs a summary indicating
the number of tests and their runtime. The
OK
message indi
-
cates that all tests passed.

RUNNING A
FAILING T ES
T
What does a failing test look like?
What can you learn from a failing test?
How do you ˜x a failing test?
What does
setUp()
do in a test case?
How can you use
setUp()
to make your
testing code more ef˜cient?
What is a package?
What is a library?
What is
pip
?
How do you install Python packages?
How do you uninstall a Python package?
How do you write an
if
-
else
statement?
How do you write a series of
if
-
elif
-
else

statements?
What is a programming language?
What™s unique about Python?
How does a programming language affect
the way we think about solving problems?

You might also like