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
Q

define is-a

A

A phrase to say that something inherits from another, as in a “salmon” is-a “fish”

26
Q

define has-a

A

A phrase to say that something is composed of other things or has a trait, as in “ a salmon has-a mouth”

27
Q
translate
class X(Y)
A

Make a class name X that is-a Y

28
Q
translate
class X(object): def \_\_init\_\_(self, J)
A

class X has-a __init__ that takes self and J parameters

29
Q

foo = X()

A

set foo to an instance of class X

30
Q

foo.M(J)

A

From foo get the M function and call it with parameters self, J

31
Q

foo.K = Q

A

From foo get the K attribute and set it to Q

32
Q

What is an ordinal number?

A

They indicate the order of things, like a list of who came in what place in a race.

33
Q

What is a cardinal number?

A

Cardinal numbers start at 0 and can be accessed randomly without cycling through the numbers before the number you are looking for.

34
Q

How does Zed Shaw feel about Dijkstra?

A

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
Q

Should boolean tests in if-statements be complex?

A

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
Q

Does Zed Shaw think you should use a debugger?

A

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
Q

define as

A

Part of the with-as statement

with X as Y: pass

38
Q

define assert

A

Assert (ensure) that something is true

assert False, “Error!”

39
Q

define from

A
import specific parts of a module
import X from Y
40
Q

define is

A

like == to test equality

41
Q

Data Type

None

A

Represents “nothing” or “no value”

42
Q

Data Type

numbers

A

Stores only integers

43
Q

Data Type

floats

A

Stores decimals

44
Q

Data Type

lists

A

Stores a list of things

j = [1, 2, 3, 4]

45
Q

Data Type

dicts

A

Stores a key=value mapping of things

{‘x’: 1, ‘y’: 2}

46
Q

String formats

%d

A

Decimal integers (not floating point)

47
Q

String formats

%i

A

Same as %d

48
Q

String formats

%o

A

Octal number

“%o” % 1000 == 1750

49
Q

String formats

%r

A
Repr format (debugging format)
"%r" % int == ""
50
Q

operators

**

A

power of

2 ** 4 == 16

51
Q

operators

A

not equal

52
Q

@

A

At (decorators)

@classmethod

53
Q

How does Python end up translating mystuff.append(‘hello’)?

A

append(mystuff, ‘hello’)

54
Q

Translate

more_stuff.pop()

A

Call “pop” on “more_stuff”

pop(more_stuff)

55
Q

Translate

pop(more_stuff)

A

Call “pop” with argument “more_stuff”

56
Q

What is the difference between a fish and a salmon?

A

A salmon is a kind of fish, but a fish is not a kind of salmon.

57
Q

Mary is a salmon. What is the difference between mary and a salmon?

A

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
Q

Is a fish a real thing?

A

It’s a word we attach to instances of things with similar attributes.

59
Q

Is Mary the Salmon a real thing?

A

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.