DV Module 2 Variables, Comments & Input operators Flashcards

1
Q

Things to avoid when making variable names

A

avoid using reserved Keywords and Functions as they are PREDEFINED

avoid caps in the middle of the name

avoid variable name being so long that it would lead to errors in typing it

avoid anything other then _ as they will not work with naming variables

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

What is known as the assignment operator?

A

=

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

can one assign the same variable with the new value

Code:
var = 100
var = 200 + 300
print(var)
Output ?
A

Seeing a record like that, a mathematician would probably protest - no value may be equal to itself plus one. This is a contradiction. But Python treats the sign = not as equal to, but as assign a value.

output: 500

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

How would a shortcut operator look with this examples

  1. i = i + 2 * j
  2. var = var / 2
  3. rem = rem % 10
  4. j = j - (i + var + rem)
  5. x = x ** 2
A
  1. i += 2 * j
  2. var /= 2
  3. rem %= 10
  4. j -= (i + var + rem)
  5. x **= 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Exercise

What is the output of the following snippet?

var = 2
var = 3
print(var)

A

3

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

Exercise

Which of the following variable names are wrong in Python?

my_var

m

101

averylongvariablename

m101

m 101

Del

del

A

101 # incorrect (starts with a digit)

m 101 # incorrect (contains a space)

Del # incorrect (is a keyword)

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

Exercise

What is the output of the following snippet?

a = ‘1’
b = “1”
print(a + b)

A

11

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

Exercise

What is the output of the following snippet?

a = 6
b = 3
a /= 2 * b
print(a)

A

1.0

2 * b = 6
a = 6 → 6 / 6 = 1.0

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

How do you make a comment Python

A

use a # at the start of a line

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

The _____ function is able to read data entered by the user and to return the same data to the running program.

A

input ()

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

Two different type casting for function input()

A

int(input()

float(input()

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

What is another use for + $ * other then adding or multiplying operators?

A

adding and multiplying strings together.

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

The meaning of the positional parameter is determined by its:

Position

Appearance

Name

A

Position

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