2 Key takeaways Flashcards
(42 cards)
notations for representing some fixed values in code. Python has various types of literals - for example, a literal can be a number (numeric literals, e.g., 123), or a string (string literals, e.g., “I am a literal.”).
Literals
system of numbers that employs 2 as the base. Therefore, a binary number is made up of 0s and 1s only, e.g., 1010 is 10 in decimal.
binary system
Octal and Hexadecimal facts
Octal and hexadecimal numeration systems, similarly, employ 8 and 16 as their bases respectively. The hexadecimal system uses the decimal numbers and six extra letters.
Integers (or simply ints) are one of the numerical types supported by Python
They are numbers written without a fractional component, e.g., 256, or -1 (negative integers).
one of the numerical types supported by Python. They are numbers that contain (or are able to contain) a fractional component, e.g., 1.27.
Floating-point numbers (or simply floats)
To encode quote inside a string you can either use
escape character, e.g., ‘I'm happy.’, or open and close the string using an opposite set of symbols to the ones you wish to encode, e.g., “I’m happy.”
to encode an apostrophe, and ‘He said “Python”, not “typhoon”’ to encode a (double) quote.
apostophre
two constant objects True and False used to represent truth values (in numeric contexts 1 is True, while 0 is False.
Boolean Values
There is one more, special literal that is used in Python: the None literal. This literal is a so-called NoneType object, and it is used to represent
the absence of a value
“Hello “, “007”
strings/string literals.
“1.5”
2.0
528
False
The first is a string,
second is a numerical literal (a float),
third is a numerical literal (an integer),
fourth is a boolean literal.
What is the decimal value of the following binary number?
1011
It’s 11, because
(20) + (21) + (2**3) = 11
symbol of the programming language, which is able to operate on the values.
operator
For example, just as in arithmetic, the + (plus) sign is the operator which is able to add two numbers, giving the result of the addition.
operators which are associated with the most widely recognizable arithmetic operations:
+, -, *, /, //, %, **
Please excuse my dear aunt sally
parentheses
exponents
multiplication
division
addition
subtraction
data and operators when connected toghether form
expressions. The simplest expression is a literal itself.
combination of values (or variables, operators, calls to functions ‒ you will learn about them soon) which evaluates to a certain value, e.g., 1 + 2.
expression
special symbols or keywords which are able to operate on the values and perform (mathematical) operations, e.g., the * operator multiplies two values: x * y.
Operators
+ (addition), - (subtraction), * (multiplication), / (classic division ‒ always returns a float), % (modulus ‒ divides left operand by right operand and returns the remainder of the operation, e.g., 5 % 2 = 1), ** (exponentiation ‒ left operand raised to the power of right operand, e.g., 2 ** 3 = 2 * 2 * 2 = 8), // (floor/integer division ‒ returns a number resulting from division, but rounded down to the nearest whole number, e.g., 3 // 2.0 = 1.0)
Arithmetic operators in Python
operator is an operator with only one operand, e.g., -1, or +3.
unary
operator is an operator with two operands, e.g., 4 + 5, or 12 % 5.
binary
Some operators act before others – the hierarchy of priorities:
the ** operator (exponentiation) has the highest priority;
then the unary + and - (note: a unary operator to the right of the exponentiation operator binds more strongly, for example: 4 ** -1 equals 0.25)
then *, /, //, and %;
and, finally, the lowest priority: the binary + and -.
are always calculated first, e.g., 15 - 1 * (5 * (1 + 2)) = 0.
Subexpressions in parentheses
The exponentiation operator uses
right-sided binding, e.g., 2 ** 2 ** 3 = 256.