strings in python

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/32

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

33 Terms

1
New cards

string

A sequence of characters inside quotes (” “ or ’ ’).

2
New cards

Can strings contain spaces, digits, or special characters?

Yes, they can contain all of those.

3
New cards

Are strings mutable or immutable in Python?

| Immutable (cannot be changed directly, but new strings can be created).

4
New cards

How do you access the first character of a string?

string[0].

5
New cards

How do you access the last character of a string?

string[-1].

6
New cards

What is slicing?

Extracting a part of a string: string[start:end:step]

7
New cards

What does len(string) return?

The number of characters in the string.

8
New cards

How to concatenate strings?

With +

9
New cards

How to repeat a string?

With * (e.g., “Hi” * 3 → “HiHiHi”)

10
New cards

What does \n mean?

New line

11
New cards

What does \t mean?

Tab

12
New cards

What does \ mean?

A backslash

13
New cards

What is a raw string?

A string with r”” that treats backslashes literally (e.g., r”C:\new\test”)

14
New cards

What does .upper() do?

Converts string to uppercase

15
New cards

What does .replace(“old”,“new”) do?

Replaces substring with new text

16
New cards

What does .find(“sub”) do?

Returns index of first match, or -1 if not found

17
New cards

What are 3 main ways to format strings?

f-strings, .format(), % operator

18
New cards

Example of f-string?

f”My name is {name}”

19
New cards

Example of .format()?

“My name is {}”.format(name)

20
New cards

Example of % operator?

“My name is %s” % name

21
New cards

What is regex used for?

Pattern matching in strings

22
New cards

Common regex functions?

search, findall, split, sub

23
New cards

What does \d match?

Any digit

24
New cards

What does \D match?

Any non-digit

25
New cards

What does \w match?

Any word character (letters, digits, _)

26
New cards

What does \W match?

Any non-word character

27
New cards

What does \s match?

Any whitespace

28
New cards

What does \S match?

Any non-whitespace

29
New cards

What does \b match?

Word boundary

30
New cards

What does \B match?

Not at word boundary

31
New cards

What does re.split(r”\s”, text) do?

Splits text by whitespace

32
New cards

What does re.sub(pattern, replacement, text do?

) | Replaces matches with replacement

33
New cards