2: Variables, Expressions, Statements Flashcards
What is a type?
Each separate value can be categorized under one of these. Some of these categories include: integer (numbers), float (numbers with decimal points) and string (sequence of letters)
Note: strings must be contained by quotation marks.
What is a value?
One of the basic things a program works with, such as a letter or a number.
What does Python do with commas in large integers?
> > > print 1,000,000
100
Python interprets commas as a seperation between a sequence of integers, which it then prints with spaces in between.
What is a variable?
A name that refers to a value.
What is an assignment statement?
This creates new variables and gives them values.
EX of three various ________:
> > > message= “let’s do something”
N = 17
pi = 3.14159265
What is a statement?
A unit of code that the Python interpreter can execute.
What is an operator?
Special symbols that represent computations like addition and multiplication.
What are operands?
The values the operator is applied to.
What is floor division?
An operation that is performed between two integers this producing a third integer as the result.
Ex. 9/10 = 0
8/3 = 2
What is floating point division?
A division function where at least one floating point number is involved, thus producing an answer as a float or number including a decimal point.
Ex. 59/60.0 = .98333333
What is an expression?
A combination of values, variables, and operators. In addition, a value or a variable is considered an expression all by itself.
What are the rules of precedence? Think of algebra.
PEMDAS
Parentheses
Exponentation
Multiplication or Division (left to right)
Addition or Subtraction (left to right)
What is the modulus operator?
An equation that works on integers and yields the remainder when the first operands is divided by the second. In Python, the operator for this equation is %
> > > quotient = 7/3
print quotient
2
> > > remainder = 7%3
print remainder
1
What is concatenation?
The joining of strings by linking them end to end.
> > > first = ‘100’
second = ‘150’
print first + second
100150
raw_input
A built in function within Python which when the function is called, the program stops and waits for the user to type something.
Then, once the user presses return or enter, the program returns what the user typed as a string
> > > input = raw_input ()
Hi there computer
print input
Hi there computer