Learn Python the Hard Way Flashcards

1
Q

names for “#”

A

octothorpe, mesh, hash, pound

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

how to write less than or equal to, more than or equal to

A

=

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

what does the acronym PEMDAS stand for in math?

A
the order of operations:
parenthesis
exponents
multiplication
division
addition
subtraction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between = and == in python?

A

= assigns the value on the right to the variable on the left. The == tests if both sides have the same value.

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

Which is good python formatting:
x=100
x = 100

A

x = 100

There should be a space before and after an operator.

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

How do you embed variables in a string?

A

By using a specialized format sequence and then putting the variables at the end with a special syntax that tells Python “Hey this is a format string. Put these variables in there.”

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

What is the general purpose of a string?

A

It’s usually something you want to display or “export” out of a program.

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

What is the maximum number of characters you should have in a line of Python code?

A

80

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

Are single or double quotes better for short strings?

A

Single quotes are considered better

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

What are the triple quotes (“””) used for?

A

You can use the triple quotes to enter a long string with newlines.

ex:
"""
Hello
this is
a long
string
"""
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why would you use a comma after a print statement?

A

To avoid creating a newline after that print statement.

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

What is the terminal command for reading python documentation?

A

pydoc

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

What does the shorthand notation += mean?

A
It's a contraction of = and +
So:
x = x + y
and 
x += y
are the same
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Python is called an “object oriented programming language.” What does that mean?

A

This means there is a construct in Python called a class that lets you structure your software in a particular way. Using classes, you can add consistency to your programs so that they can be used in a cleaner way. At least that’s the theory.

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

What is a class?

A

A class is a way to take a grouping of functions and data and place them inside a container so you can access them with the . (dot) operator.

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

What is instantiate?

A

If a class is like a “mini-module,” then there has to be a similar concept to import but for classes. That concept is called “instantiate”, which is just a fancy, obnoxious, overly smart way to say “create.” When you instantiate a class what you get is called an object.

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

define class

A

Tell Python to make a new type of thing

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

define object

A

Two meanings:
the most basic type of thing
any instance of some thing

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

define instance

A

What you get when you tell Python to create a class

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

define def

A

How you define function inside a class

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

define self

A

Inside the functions in a class, self is a variable for the instance/object being accessed

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

define inheritance

A

The concept that one class can inherit traits from another class, much like you and your parents

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

define composition

A

The concept that a class can be composed of other classes as parts, much like how a car has wheels

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

define attribute

A

A property classes have that are from composition and are usually variables

25
define is-a
A phrase to say that something inherits from another, as in a "salmon" is-a "fish"
26
define has-a
A phrase to say that something is composed of other things or has a trait, as in " a salmon has-a mouth"
27
``` translate class X(Y) ```
Make a class name X that is-a Y
28
``` translate class X(object): def __init__(self, J) ```
class X has-a __init__ that takes self and J parameters
29
foo = X()
set foo to an instance of class X
30
foo.M(J)
From foo get the M function and call it with parameters self, J
31
foo.K = Q
From foo get the K attribute and set it to Q
32
What is an ordinal number?
They indicate the order of things, like a list of who came in what place in a race.
33
What is a cardinal number?
Cardinal numbers start at 0 and can be accessed randomly without cycling through the numbers before the number you are looking for.
34
How does Zed Shaw feel about Dijkstra?
He recommends you avoid his writings on cardinal numbers unless you enjoy being yelled at by someone who stopped programming at the same time programming started.
35
Should boolean tests in if-statements be complex?
No they should be simple. If they are complex, move their calculations to variables earlier in your function and use a good name for the variable.
36
Does Zed Shaw think you should use a debugger?
Nope. A debugger is like doing a full-body scan on a sick person. You do not get any specific useful information and you find a whole lot of information that doesn't help and is just confusing.
37
define as
Part of the with-as statement | with X as Y: pass
38
define assert
Assert (ensure) that something is true | assert False, "Error!"
39
define from
``` import specific parts of a module import X from Y ```
40
define is
like == to test equality
41
Data Type | None
Represents "nothing" or "no value"
42
Data Type | numbers
Stores only integers
43
Data Type | floats
Stores decimals
44
Data Type | lists
Stores a list of things | j = [1, 2, 3, 4]
45
Data Type | dicts
Stores a key=value mapping of things | {'x': 1, 'y': 2}
46
String formats | %d
Decimal integers (not floating point)
47
String formats | %i
Same as %d
48
String formats | %o
Octal number | "%o" % 1000 == 1750
49
String formats | %r
``` Repr format (debugging format) "%r" % int == "" ```
50
operators | **
power of | 2 ** 4 == 16
51
operators
not equal
52
@
At (decorators) | @classmethod
53
How does Python end up translating mystuff.append('hello')?
append(mystuff, 'hello')
54
Translate | more_stuff.pop()
Call "pop" on "more_stuff" | pop(more_stuff)
55
Translate | pop(more_stuff)
Call "pop" with argument "more_stuff"
56
What is the difference between a fish and a salmon?
A salmon is a kind of fish, but a fish is not a kind of salmon.
57
Mary is a salmon. What is the difference between mary and a salmon?
Mary is a specific instance of a salmon. She was created from some other salmon and now she represents a real thing that has Salmon-like attributes. Fish is a class, salmon is a class, Mary is an object.
58
Is a fish a real thing?
It's a word we attach to instances of things with similar attributes.
59
Is Mary the Salmon a real thing?
Yes it is an instance of Fish, an object, a real thing. Mary is a kind of salmon that is a kind of fish: an object is a class is a class.