Python 3 Flashcards

1
Q

What is the function that converts number into a string?

A

str()

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

How to make exponential operator?

A

Using two asterisks **

The format for exponentiation in Python is a number or variable followed by the operator ** followed by a numer or variable which represents the power to raise the number. Both the number and the power can be integer or floating point values.

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

What does the modulo do?

A

A modulo calculation returns the remainder of a division between the first and second number.

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

What is the syntax to write a function?

A

To write a function, you must have a heading and an indented block of code. The heading starts with the keyword def and the name of the function, followed by parentheses, and a colon. The indented block of code performs some sort of operation.

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

What is the difference beween positional arguments and keyword arguments?

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

When you give an argument a default value (making it a keyword argument), what should you remember in term of positioning of this argument?

A

No arguments that follow can be used positionally.

Any number of arguments in a function can have a default value. But once we have a default argument, all the arguments to its right must also have default values. This means to say, non-default arguments cannot follow default arguments.

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

When using the print() function to print string + value, the value needs first to be…

A

…converted into a string.

To do so, we use the str() function

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

Which variables can be called in the blank spot in this code:

A

Just counter

new_counter is ‘local’ to the function. Thus, it cannot be reached from outside the function body.

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

How does the prompt look like in Python?

A

>>>

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

What is the function that output the type of a variable

A

type() method returns class type of the argument(object) passed as parameter. type() function is mostly used for debugging purposes.

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

Is the code below correct?

A

No. We need to use the double equal sign ( == ) as lines 2 and 4 are boolean expressions within a conditional statement.

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

When it comes to conditional statements, when we’re evaluating whether expression are true or false and run a bloc of code, what do we need to be cautious about with the equal sign?

A

We need to use the double equal sign for a boolean expression

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

Give 3 Boolean Operators (also known as “Logical Operators”)

A

and

or

not

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

How to determine if numbers are multiple of 5

A

Using modulo. If the returned remainder is zero, then it means the number was a multiple of 5.

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

What will be the output of those lines?

A

The .sort() Python list method will sort the contents of whatever list it is called on. Numerical lists will be sorted in ascending order, and lists of strings will be sorted into alphabetical order. It modifies the original list, and has no return value!

Here our variable sorted_cities hasn’t been assigned any value since the sort() has no return value.

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

What will be the output of this?

A
17
Q

What will be the output of those lines?

A
18
Q

What will be the output of:

x = range(5)

for n in x:
print(n)

A

0
1
2
3
4

19
Q

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and…

A

…stops before a specified number