Python Basic Flashcards
Exponent Operator and example
**
2**3 = 8
Modulus/remainder operator and example
%
7%5 = 2
Integer division/floored quotient operator and example
// 12//5 = 2
Division operator and example
/
12/5=2.4
Multiplication operator and example
*
2*5=10
Subtraction operator and example
-
5-2=3
Addition operator and example
+
5+2=7
What is the order of operations (also called precedence) of Python math operators?
** % // / * - \+
What are expressions?
values combined with operators, and they always evaluate down to a single value
What are the most common data type in python?
integers = -2, 5, 6
Floating-point numbers(float) = 2.44
strings = a, b ,c
What does it mean?
SyntaxError: EOL while scanning string literal
you probably forgot the final single quote character at the end of the string
EOL stands for end of line
What is the string concatenation operator?
+
‘Bob’ + ‘ ‘ + ‘ Dylan’
Bob Dylan
What does it mean?
TypeError: can only concatenate str (not “int”) to str
‘Bob’ + 25
we cannot use + to concatenate strings and integers
What is string replication operator?
‘Bob’*5 (this should be a value, it cannot be a string)
‘BobBobBobBobBob’
What is an assignment statement?
Spam = 25
variable name, an equal sign (called the assignment operator), and the value to be stored
How to change the value of a variable?
by assigning a new value to it
What are the variable names rules?
It can be only one word with no spaces.
It can use only letters, numbers, and the underscore (_) character.
It can’t begin with a number.
different way of naming a value?
camelCase
PascalCase
snake_case
How to ask for user’s input?
myAge = input()
How to write a comment in python?
or
””” “””
How to use print function to put a blank line on the screen?
just call print() with nothing in between the parentheses.
what value type does input() function return?
only string
How to convert value type in python?
str(42)
int(‘42) , int(age)
float(‘42.5’)
function to round a number?
round(2.5555, 2)
2.55