Arithmetic Expressions Flashcards
What algebraic rules does Python adhere to?
PEMDAS
What happens when you mix an integer and floating-point value in an arithmetic expression?
results in a floating-point value
ex. 7+4.0
–> 11.0
What happens when you mix strings with integers or floating point values?
error
how are powers shown?
**
What is floor division? What is its operator?
//
divides but drops the fractional part:
ex. 7//4 = 1 (drops 0.75)
How can you calculate a remainder? What is its operator?
%
ex. remainder = 7%4
–> 3
aka modulo divide/modulus
What is a function?
a collection of programming instructions that carry out a particular task
What are built-in functions?
small set of functions that are defined as a part of the python language
What are examples of built-in functions?
abs(x)
round(x)
max(x1,x2,…,xn)
min(x1,x2,…xn)
What is a library?
collection of code written and compiled by someone else that is ready for you to use in your program
What is a standard library?
a library that is considered part of the language and use be included with any Python system
how is python’s standard library organized?
with modules – related functions and data types are grouped in the same module
What must be done before using functions in a program?
functions defined in a module must be explicitly loaded into the program
ex.
from math import sqrt
y = sqrt(x)
how do you import a function from a module?
from (module) import (function)
from (module) import * (imports all functions)
import (module) (imports all functions)
–> must include module.function
ex. import math
y=math.sqrt(x)
What are the rules of parentheses?
at ANY POINT in an expression “(“ ≥ “)”
at the END of the expression “(“ = “)”