Python 3 Flashcards
What is the function that converts number into a string?
str()
How to make exponential operator?
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.
What does the modulo do?
A modulo calculation returns the remainder of a division between the first and second number.
What is the syntax to write a function?
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.
What is the difference beween positional arguments and keyword arguments?
When you give an argument a default value (making it a keyword argument), what should you remember in term of positioning of this argument?
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.
When using the print() function to print string + value, the value needs first to be…
…converted into a string.
To do so, we use the str() function
Which variables can be called in the blank spot in this code:
Just counter
new_counter is ‘local’ to the function. Thus, it cannot be reached from outside the function body.
How does the prompt look like in Python?
>>>
What is the function that output the type of a variable
type() method returns class type of the argument(object) passed as parameter. type() function is mostly used for debugging purposes.
Is the code below correct?
No. We need to use the double equal sign ( == ) as lines 2 and 4 are boolean expressions within a conditional statement.
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?
We need to use the double equal sign for a boolean expression
Give 3 Boolean Operators (also known as “Logical Operators”)
and
or
not
How to determine if numbers are multiple of 5
Using modulo. If the returned remainder is zero, then it means the number was a multiple of 5.
What will be the output of those lines?
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.