Learn Python the Hard Way Flashcards
names for “#”
octothorpe, mesh, hash, pound
how to write less than or equal to, more than or equal to
=
what does the acronym PEMDAS stand for in math?
the order of operations: parenthesis exponents multiplication division addition subtraction
What is the difference between = and == in python?
= assigns the value on the right to the variable on the left. The == tests if both sides have the same value.
Which is good python formatting:
x=100
x = 100
x = 100
There should be a space before and after an operator.
How do you embed variables in a string?
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.”
What is the general purpose of a string?
It’s usually something you want to display or “export” out of a program.
What is the maximum number of characters you should have in a line of Python code?
80
Are single or double quotes better for short strings?
Single quotes are considered better
What are the triple quotes (“””) used for?
You can use the triple quotes to enter a long string with newlines.
ex: """ Hello this is a long string """
Why would you use a comma after a print statement?
To avoid creating a newline after that print statement.
What is the terminal command for reading python documentation?
pydoc
What does the shorthand notation += mean?
It's a contraction of = and + So: x = x + y and x += y are the same
Python is called an “object oriented programming language.” What does that mean?
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.
What is a class?
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.
What is instantiate?
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.
define class
Tell Python to make a new type of thing
define object
Two meanings:
the most basic type of thing
any instance of some thing
define instance
What you get when you tell Python to create a class
define def
How you define function inside a class
define self
Inside the functions in a class, self is a variable for the instance/object being accessed
define inheritance
The concept that one class can inherit traits from another class, much like you and your parents
define composition
The concept that a class can be composed of other classes as parts, much like how a car has wheels