Programming (python) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Multiple line strings (python)

A

””” or ‘’’

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

Single character from string

A

StringName[position]

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

Loop through characters in a string

A

iteration loop (for i in StringName and StringName[i])

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

Range of characters from string (python)

A

(StringName [position1:position2])

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

What points would (StringName [position1:position2]) take from a string?

A

From before position 1 to before position 2

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

Take a slice from first/last position of a string

A

(StringName[ :position2])
(StringName[position1: ])

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

Slice position relative to the end of a string (python)

A

StringName[position-2:position-1]

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

Rule for slice position relative to the end of a string

A

the last position in a string is -1, not -0

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

Concatenate strings

A

String1 + String2

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

Change format of another variable then concatenate into a placeholder (python)

A

String.format(Var1, Var2) where string contains placeholder marked {}
e.g:
txt2 = “My name is {0}, I’m {1}”.format(“John”,36)

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

Find length of string (python)

A

len(StringName)

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

Change string to all upper/lower case (python)

A

StringName.upper()
StringName.lower()

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

Remove whitespace from beginning/end of a string

A

StringName.strip()

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

Replace characters in a string

A

StringName.replace(“oldstring”, “newstring”)

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

Create a list of substrings by identifying a separator in a string (python)

A

StringName.split(“separator”)
e.g. ‘,’
Removes separator from all substrings

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

Check for a section in a string (python)

A

“section” in StringName
Returns Boolean value

17
Q

Default case for a matchcase statement

A

case _:

18
Q

Set a variable for a matchcase statement

A

match Variable1: