Topic 1 - Session 1 - MTA Intro Course Flashcards
Describe three core aspects of defining a variable
- Variables cannot have spaces in their names
- Variables are case-sensitive
- Variables cannot begin with a number
Which type of variable use decimals?
Floating
Describe what a variable is in simple terms
A variable is a container that can be used to store information which can be used later.
When declaring variables in python, what is best practice?
It is best practice to use camel casing.
What punctuation symbol should we use to combine strings and numbers in a print statement?
A comma
Explanation:
A comma removes the need to convert the integer to a string.
How many values does a Boolean variable have?
Two values - either True or False
What is ‘\n’ called and what does it do?
It is called an escape character and it is used to send text to a new line.
Are Boolean values case sensitive?
Yes, the values can only be either True or False
What is type casting in Python?
This is when you convert a integer or a float value into a string
str(variable_name)
When converting a float to an integer, what must you keep in mind?
The casting will result in the float number being rounded down.
Lists are known as what in other programming languages?
Arrays
Lists use what type of brackets?
Square brackets
list = [ ‘dog’ ]
How would you add a new value to the end of this list?
list = [ ‘dog’ ]
list.append(‘cat’)
How would you remove a value from a list?
list.remove(‘dog’)
How would you sort a list in alphabetical order?
list.sort()
Instead of using list.append to add a value to the end of a list, what other command could be used?
list[-1] = ‘bat’
Note: This will replace the existing last value in the list.
What is the difference between a single equals sign and a double equals sign?
- A single equals sign is known as an assignment
2. A double equals sign is asking whether something is equal
Name the three logical operators
and
or
not
When you use the ‘and’ logical operator, what is the logic being asked?
This means both sides of the statement must be true.
a == c and b != c
When you use the ‘or’ logical operator, what is the logic being asked?
This means that only one side of the statement must be true.
When you use the ‘not’ logical operator, what is the logic being asked?
This means that statements are checked for the opposite.
In python, what does the percentage sign % do?
It is used for modulus which is used to find a remainder after a division.
What does this mean in python
8 ** 3
** means exponent, other known as 8 raised to the power of 3
What is the identity operator do?
This is used to determine if two variables have the same ID.
What is the containment operator?
It is either ‘in’ or ‘not in’
It is used to determine if a list does or does not contain something.