3.2.8 - String handling operations in a programming language Flashcards

(7 cards)

1
Q

length

A

Determines the number of characters in a string, including spaces and punctuation.​

len(“Hello”) - # returns 5

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

Position

A

Finds the index of a specified character or substring within a larger string.

text = “computer”
position = text.find(“p”)
print(position) - # returns “3”

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

Substring

A

Extracts a portion of a string, defined by a starting position and length or end position.​

“computer”[1:4] - # returns “omp”

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

Concatenation

A

Joining two or more strings end-to-end to form a new string.

“Hello “ + “World” - # returns “Hello World”

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

Convert character to character code

A

Returns the numerical code (e.g., ASCII) for a character.

ord(‘A’) # returns 65

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

Convert character code to character

A

Returns the character represented by a character code.

chr(66) # returns ‘B’

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

String conversion operations

A

int(“42”) # string to integer → 42
float(“3.14”) # string to real → 3.14
str(99) # integer to string → “99”
str(2.5) # real to string → “2.5”

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