Topic 1 - Session 1 - MTA Intro Course Flashcards

1
Q

Describe three core aspects of defining a variable

A
  1. Variables cannot have spaces in their names
  2. Variables are case-sensitive
  3. Variables cannot begin with a number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which type of variable use decimals?

A

Floating

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

Describe what a variable is in simple terms

A

A variable is a container that can be used to store information which can be used later.

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

When declaring variables in python, what is best practice?

A

It is best practice to use camel casing.

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

What punctuation symbol should we use to combine strings and numbers in a print statement?

A

A comma

Explanation:
A comma removes the need to convert the integer to a string.

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

How many values does a Boolean variable have?

A

Two values - either True or False

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

What is ‘\n’ called and what does it do?

A

It is called an escape character and it is used to send text to a new line.

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

Are Boolean values case sensitive?

A

Yes, the values can only be either True or False

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

What is type casting in Python?

A

This is when you convert a integer or a float value into a string

str(variable_name)

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

When converting a float to an integer, what must you keep in mind?

A

The casting will result in the float number being rounded down.

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

Lists are known as what in other programming languages?

A

Arrays

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

Lists use what type of brackets?

A

Square brackets

list = [ ‘dog’ ]

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

How would you add a new value to the end of this list?

list = [ ‘dog’ ]

A

list.append(‘cat’)

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

How would you remove a value from a list?

A

list.remove(‘dog’)

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

How would you sort a list in alphabetical order?

A

list.sort()

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

Instead of using list.append to add a value to the end of a list, what other command could be used?

A

list[-1] = ‘bat’

Note: This will replace the existing last value in the list.

17
Q

What is the difference between a single equals sign and a double equals sign?

A
  1. A single equals sign is known as an assignment

2. A double equals sign is asking whether something is equal

18
Q

Name the three logical operators

A

and
or
not

19
Q

When you use the ‘and’ logical operator, what is the logic being asked?

A

This means both sides of the statement must be true.

a == c and b != c

20
Q

When you use the ‘or’ logical operator, what is the logic being asked?

A

This means that only one side of the statement must be true.

21
Q

When you use the ‘not’ logical operator, what is the logic being asked?

A

This means that statements are checked for the opposite.

22
Q

In python, what does the percentage sign % do?

A

It is used for modulus which is used to find a remainder after a division.

23
Q

What does this mean in python

8 ** 3

A

** means exponent, other known as 8 raised to the power of 3

24
Q

What is the identity operator do?

A

This is used to determine if two variables have the same ID.

25
Q

What is the containment operator?

A

It is either ‘in’ or ‘not in’

It is used to determine if a list does or does not contain something.