Ch 2. Flashcards

1
Q

What does ending .py mean?

A

The file is a python file

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

What is a variable?

A

A symbolic representation of a value, can think of as a label for a value

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

Rules for naming and using variables

A
  1. Variable names can only contain letters, numbers and underscores.
  2. Can start with a letter or underscore but NOT a number.
  3. Spaces are not allowed
  4. Do not use Python keywords and function names. (aka reserved words)
  5. Names should be short but descriptive.
  6. Be careful using lowercase l and uppercase O because it can be confused with 1 and 0.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a string?

A

a series of characters

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

change to upper case for first letters only?

A

variable_name.title()

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

all upper case?

A

variable_name.upper()

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

all lower case?

A

variable_name.lower()

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

format strings

A

Python formats the string by replacing the name of any variable in braces with its value:
f”Hello, {variable_name}!”

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

\t

A

adds tab

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

\n

A

adds new line

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

How to remove whitespace temporarily? Permanently?

A
Temp:
all: variable_name.strip()
for right: variable_name.rstrip()
or for left:  variable_name.lstrip()
Perm: You have to associate the stripped value with the variable name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When does a syntax error occur?

A

When python doesn’t recognize a section of your program as valid code.

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

How do you assign values to more than one variable using a single line of code?

A

Using multiple assignment: x, y, z = 0, 0, 0

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

How do you indicate a constant?

A

Using all caps. For example: MAX_CONNECTIONS = 5000

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