Python 3 Flashcards

1
Q

What are the four rules to naming variables?

A
  1. Variables are case sensitive.
  2. Variable names must be one word.
  3. Variable names may be letters, numbers, or underscore.
  4. Variable names cannot begin with a number.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Variables should begin with a ________ word, and multiple words should be separated with _________s.

A

lowercase , underscore

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

How do you assign an integer to a variable?

A
variable = integer
x = 100
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you assign a string to a variable?

A
variable = 'string'
x = 'wes'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you print a variable?

A

print(variable)

print(x)

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

How do you assign multiple values to the same value?

A
variable1 = variable2 = variable3 = integer
x = y = z = 0
x = y = z = 'wes'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you assign values to several different variables within the same line?

A

variable1, variable2, variable3 = value1, value2, value3

x, y, z = 1, ‘two’, 3

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

What is a global variable?

A

A global variable exists outside a function.

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

What is a function?

A

A function is a block of instructions that performs an action and, once defined, can be reused. Functions make code more modular, allowing you to use the same code over and over again.

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

What is a local variable?

A

A local variable exists within a function.

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

What is the python function to return an absolute value?

A

abs ( )

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

What are the five python data types?

A
  1. Numbers
  2. String
  3. List
  4. Tuple
  5. Dictionary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the three python numerical types?

A
  1. Integer
  2. Float
  3. Complex
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the code to print the first letter in a string?

A

print(stringname[0])

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

What is a list?

A

A list contains items separated by columns and enclosed with brackets.

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

What is the code to create a list?

A

list = [1,2,4,’four’,5]

17
Q

What is the code to print the 2 through 4th items in a list?If

A

print(list[1:4])

18
Q

What is a tuple?

A

A tuple is a list of numbers separated by comma’s and enclosed in parenthesis.

19
Q

What is the code to create a tuple?

A

tuple = (1,2,3, ‘four,5)

20
Q

What is the major difference between a tuple and a string?

A

Tuple items cannot be changed, they are read only.

21
Q

What are the 7 arithmetic operators supported by python?

A
  1. addition +
  2. Multiplication *
  3. Subtraction -
  4. Division /
  5. modulus %
  6. Exponent **
  7. Floor //
22
Q

What is floor division?

A

The division of operands where the result is the quotient with any numbers after the decimal dropped. If one of the operands is negative then the result will be negative.

23
Q

What are the 6 python comparison operators?

A
  1. If the value of two operands is equal then the condition becomes true. ==
  2. If the value of two operands are not equal, then the condition becomes true. !=
  3. If the value of the left operand is greater than the right operand then the condition becomes true. >
  4. If the value of the right operand is great than the left operand then the condition becomes true. <
  5. If the value of the left operand is greater than or equal to the right then the condition becomes true. >=
  6. If the value of the right operand is greater then or equal to the left operand then the condition becomes true. <=
24
Q

What are the three python decision making statements?

A
  1. If statement
  2. If…else statement
  3. Nested if statement.
25
Q

What is the code for a single if statement?

A

if variable == 1:

print(‘True’)

26
Q

What is the code for a if… else statement?

A

if variable == 1:
print(‘True’)
Else:
print(‘False’)