DV Module 2 Functions & Operators Flashcards

1
Q

What print is an example of a

A

Function name

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

Can you make your own functions in Python

A

Yes you can and the name should be significant to its use.

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

Anything thing between quotes will be taken literally, not as code but as_____.

A

Data which is string

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

A functions_name and a argument(s) forms a

A

function invocation

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

Steps the code takes to use a Function(argument)

A
  1. checks of the name is LEGAL]
  2. allows you to invoke; make sure there is the correct amount of functions.
  3. Leaves your code for a moment; jumps into the function you want to invoke.
  4. Executes its code; causes the desired effect
  5. returns to your code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Two ways you can create a newline or and emptyline

A
empty print()
\n
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why would one use , in an argument?

A

To put more then one argument in the string

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

what is the keyword ‘end=’ used for

Code:
print(“My name is “, end=””)
print(“Monty Python.”)

A

to tell the code to keep the next argument on the same line of code.

Output:
My name is Monty Python.

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

what is keyword ‘sep=’ used for

Code:
print(“My”, “name”, “is”, “Monty”, “Python.”, sep=”-“)

A

sep = separator. it is used to choose what separate’s the argument’s

Output:
print(“My”, “name”, “is”, “Monty”, “Python.”, sep=”-“)

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

Can you mix more then one Keyword argument

A

yes you can mix keyword in one invocation

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

Explane a Literal

A

Data whose values are determined by the literal itself

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

Difference between an

Integers & Floats

A

Integers: devoid of fractional parts

Floats: Numbers that contain fractional parts

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

11111111 how is this different in python to 11_111_111

A

They are the same and underscores are the only way that Python allows you to make integers easier to read.

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

What symbols are used to represent an octal&hexadeciamal number

A

‘0o’ is used for octaldecimal numbers

‘0x’ is used for hexadecimal numbers

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

what abbreviation would one use to shorten a long number such as 2_0000_0000?

A

2 * 10e8 or 2 * 10E8

Exponent: value after E must be an integer
Base: before E may or may not be an integer

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

What are Boolean values used for?

A

they’re used to represent a very abstract value - truthfulness.

17
Q

What types of literals are the following four examples?

  1. “1.5”
  2. 2.0
  3. 528
  4. False
A
  1. String
  2. Float
  3. Integer
  4. Boolean
18
Q

What is unique about the Arithmetic Operation: division?
who would we negate this unique effect

code:
print(6 / 3)
output?

A

The result is always a float

to allow division to be integer we must use “//”

print(6//3)

19
Q

What does using the ‘%’ operator do

Code:
print(14 % 4)

Output:?

A

displace the remainder of the integers being divided

14 // 4 gives 3 → this is the integer quotient;
3 * 4 gives 12 → as a result of quotient and divisor multiplication;
14 - 12 gives 2 → this is the remainder.

Output = 2

in some other codes this is called the Modulo

20
Q

Operater Bindings

Ex 1:
Code:
print(9 % 6 % 2)
Output ?

Ex 2:
Code
print(2 ** 2 ** 3)
Output?

A

Ex 1
Division is Left sided binding going from left to right

Output: from left to right: first (9 % 6) gives 3, and then (3 % 2) gives 1;

Ex 2
the exponentiation operator uses right-sided binding.

Output: (2 ** 3) → 8; (2 ** 8) → 256

21
Q

List priorities of Operators

A
  1. +, - unary A unary operator is an operator with only one operand, e.g., -1, or +3.
  2. **
  3. *, / , // , %
  4. +, - binary A binary operator is an operator with two operands, e.g., 4 + 5, or 12 % 5.
22
Q

Exercise 1

What is the output of the following snippet?

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

A

16 8.0 8

23
Q

Exercise 2

What is the output of the following snippet?

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

A

-0.5 0.5 0 -1

24
Q

Exercise 3

What is the output of the following snippet?

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

A

-2 2 512