2 Key takeaways Flashcards

1
Q

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.”).

A

Literals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

binary system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Octal and Hexadecimal facts

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Integers (or simply ints) are one of the numerical types supported by Python

A

They are numbers written without a fractional component, e.g., 256, or -1 (negative integers).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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.

A

Floating-point numbers (or simply floats)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To encode quote inside a string you can either use

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

to encode an apostrophe, and ‘He said “Python”, not “typhoon”’ to encode a (double) quote.

A

apostophre

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

two constant objects True and False used to represent truth values (in numeric contexts 1 is True, while 0 is False.

A

Boolean Values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

the absence of a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

“Hello “, “007”

A

strings/string literals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

“1.5”

2.0

528

False

A

The first is a string,

second is a numerical literal (a float),

third is a numerical literal (an integer),

fourth is a boolean literal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the decimal value of the following binary number?

1011

A

It’s 11, because
(20) + (21) + (2**3) = 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

symbol of the programming language, which is able to operate on the values.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

operators which are associated with the most widely recognizable arithmetic operations:

A

+, -, *, /, //, %, **

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Please excuse my dear aunt sally

A

parentheses
exponents
multiplication
division
addition
subtraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

data and operators when connected toghether form

A

expressions. The simplest expression is a literal itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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.

A

expression

18
Q

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.

A

Operators

19
Q

+ (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)

A

Arithmetic operators in Python

20
Q

operator is an operator with only one operand, e.g., -1, or +3.

A

unary

21
Q

operator is an operator with two operands, e.g., 4 + 5, or 12 % 5.

A

binary

22
Q

Some operators act before others – the hierarchy of priorities:

A

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 -.

23
Q

are always calculated first, e.g., 15 - 1 * (5 * (1 + 2)) = 0.

A

Subexpressions in parentheses

24
Q

The exponentiation operator uses

A

right-sided binding, e.g., 2 ** 2 ** 3 = 256.

25
Q

print((2 ** 4), (2 * 4.), (2 * 4))

A

16 8.0 8

26
Q

print((-2 / 4), (2 / 4), (2 // 4), (-2 // 4))

A

-0.5 0.5 0 -1

27
Q

print((2 % -4), (2 % 4), (2 ** 3 ** 2))

A

-2 2 512

28
Q

(2 ** 3 ** 2))

 same as

2 ** (3 ** (2 ** 1))

A

2 ** (3 ** (2 ** 1))

= 2 ** (3 ** 2)
= 2 ** 9
= 512

29
Q

named location reserved to store values in the memory. A variable is created or initialized automatically when you assign a value to it for the first time. (2.1.4.1)

A

Variable

30
Q

A legal identifier name must be a non-empty sequence of characters, must begin with the underscore(_), or a letter, and it cannot be a Python keyword. The first character may be followed by underscores, letters, and digits. Identifiers in Python are case-sensitive. (2.1.4.1)

A

Each variable must have a unique name - an identifier

31
Q

means you don’t need to declare variables in it. (2.1.4.3) To assign values to variables, you can use a simple assignment operator in the form of the equal (=) sign, i.e., var = 1.

A

Python is a dynamically-typed language

32
Q

(shortcut operators) to modify values assigned to variables, e.g., var += 1, or var /= 5 * 2. (2.1.4.8)

A

You can also use compound assignment operators

33
Q

You can assign new values to already existing variables using the assignment operator or one of the compound operators, e.g.: (2.1.4.5)

A

var = 2
print(var)

var = 3
print(var)

var += 1
print(var)

34
Q

You can combine text and variables using the + operator, and use the print() function to output strings and variables, e.g.: (2.1.4.4)

A

var = “007”
print(“Agent “ + var)

35
Q

var = 2
var = 3
print(var)

A

3

36
Q

my_var
m
101
averylongvariablename
m101
m 101
Del
del

A

my_var
m
101 # incorrect (starts with a digit)
averylongvariablename
m101
m 101 # incorrect (contains a space)
Del
del # incorrect (is a keyword)

37
Q

a = ‘1’
b = “1”
print(a + b)

A

11

38
Q

a = 6
b = 3
a /= 2 * b
print(a)

A

1.0

2 * b = 6
a = 6 → 6 / 6 = 1.0

39
Q

function sends data to the console

A

print()

40
Q

gets data from console

A

input()

41
Q

function comes with an optional parameter: the prompt string. It allows you to write a message before the user input, e.g.:

name = input(“Enter your name: “)
print(“Hello, “ + name + “. Nice to meet you!”)

A

input()

42
Q

When the input() function is called, the program’s flow is stopped

A

the prompt symbol keeps blinking (it prompts the user to take action when the console is switched to input mode) until the user has entered an input and/or pressed the Enter key.