ItP3 - String Member Function Flashcards

1
Q

What are string member functions?

A

Built-in functions in languages like Python specifically designed to operate on strings, facilitating tasks like manipulation, searching, slicing, and formatting.

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

What are some examples of string member functions? - (4)

A
  1. upper()
  2. lower()
  3. title ()
  4. strip ()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does string member function ‘upper()’ do?

A

The upper() method, converts all characters in a string to uppercase,

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

What does string member function ‘lower()’ do?

A

The lower() method, converts all characters in a string to lowercase,

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

What does string member function ‘title()’ do?

A

The title() method, , converts the first character of each word in the string to uppercase and the rest to lowercase, effectively capitalizing the first letter of each word.

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

How can you print a string in uppercase in Python and example? - (3)

A

To print a string in uppercase in Python, you can use the upper() method.

For example:
my_string = ‘the cat Sat on The Mat.’
print(my_string.upper())

Output:
MY CAT SAT ON THE MAT

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

What does string member function ‘strip’ do?

A

The strip() method, removes leading and trailing whitespace characters (such as spaces) from a string, ensuring clean and trimmed input.

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

How can you combine string member functions together? - (2)

A

You can chain string processing methods together.

For example: print(my_string.strip().lower())

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

Write a code that stores string ‘the cat Sat on The Mat’ into variable called ‘my_string’

print string in upper case

print string in lower case

print string in title case

print string and get rid of ‘whitespace’ characters (like spaces)

print string and get rid of ‘whitespace’ characters (like spaces) and print lower case as well

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

What is the output of this code?

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

Exercise:

Change the following code so that it prints the string ‘All In Title Case’ and without the leading and trailing spaces.

Bonus points. Use an f-string to center the modified string in some asterisks like this ** Hello World! **

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

Why are string member functions useful? - (2)

A

facilitate cleaning up and modifying strings, including changing their case

In scenario in which string member functions are useful is when in cases where we need to compare strings ‘case-insensitively’ (in other words without caring whether something is upper- or lower-case).

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