Unit 2 Flashcards
Variables and Expressions
2.1 - Variables and Assignments
What is a variable?
a named item that holds a value
2.1 - Variables and Assignments
What are the two types of statements in programming?
declarative: create/assign variables
executable: instructs the computer to perform a task
2.2 - Identifiers
What is an identifier?
the name of a variable
2.2 - Identifiers
What are the requirements of an identifier?
starts with a letter, can use letters, underscores, and numbers, cannot contain spaces
2.2 - Identifiers
IsnumPizzas
the same as numpizzas
?
No
2.3 - Objects
What is an object?
something that represents a value, is mutable
2.3 - Objects
What are the 3 properties of an object?
value, type, and identity
type: int, string, etc.
identity: describes object
value; number
2.3 - Objects
What is mutability?
indicates if an object’s value can be changed
2.4 - Numeric Types: Floating-Point
What is a floating-point number?
comonnly referred to as a float
a number that uses a decimal
ex. 3.14159
2.4 - Numeric Types: Floating-Point
How do you use float()
?
like int()
, it converts numbers to a float
2.4 - Numeric Types: Floating-Point
What is a floating-point literal?
a number with an unnecessary decimal
ex. 99 -> 99.0
2.4 - Numeric Types: Floating-Point
How do you round a float?
within a print statement, to nearest 100th of a decimal
print(f'{myFloat:.2f}')
2.5 - Arithmetic Expressions
What is an expression?
a combination of values that evaluates to a number
like 2 + 2
2.5 - Arithmetic Expressions
What is a literal?
a specific value indepentent of an expression
2 + 2
2.5 - Arithmetic Expressions
What type of precedence rules does Python use?
PEMDAS
parenthesis, exponents, multiplication, division, addition, subtraction