Search Header Logo
List and string methods

List and string methods

Assessment

Presentation

Science, Computers, Education

11th - 12th Grade

Medium

Created by

Akniyet Sarsenbek

Used 5+ times

FREE Resource

17 Slides • 15 Questions

1

List and string methods

By Akniyet Sarsenbek

2

Learning objectives

11.2.2.3apply functions and string processing methods;

11.2.3.3apply functions and methods of processing lists;

11.4.3.2 solve applied problems of various subject areas;

Some text here about the topic of discussion

3

Multiple Choice

String revision QUIZ

Use the len method to print the length of the string.

x = "Hello World"

1

len.x

2

print(len(x))

3

x.len()

4

print(len)

4

Multiple Choice

Get the first character of the string txt.

txt = "Hello World"

x =

1

txt(1)

2

txt(0)

3

txt[0]

4

txt[1]

5

Multiple Choice

Get the characters from index 2 to index 4 (llo).

txt = "Hello World"

x =

1

txt[2 : 5]

2

txt[2 : 4]

3

txt[2 : 6]

4

txt[1 : 5]

6

Multiple Choice

Question image

What does the following Python Program print out?

1

Hello

there

2

0

3

Hellothere

4

Hello

7

Multiple Choice

Question image

What does the following Python program print out?

1

x2

2

int402

3

402

4

42

8

Multiple Choice

How would you use the index operator [] to print out the letter q from the following string?

x = 'From marquard@uct.ac.za'

1

print(x[q])

2

print(x[8])

3

print(x[9])

4

print(x[7])

9

Multiple Choice

How would you use string slicing [:] to print out 'uct' from the following string?

x = 'From marquard@uct.ac.za'

1

print(x[14:3])

2

print(x[14:17])

3

print(x[15:18])

4

print(x[14/17])

10

Multiple Choice

Question image

What does the following Python code print out?

1

banana7

2

42

3

-1

4

banana banana banana banana banana banana banana

11

String methods

count() method

Return the number of times the value "apple" appears in the string:

txt = "I love apples, apple are my favorite fruit"

x = txt.count("apple")

print(x)

Some text here about the topic of discussion

12

find() method​

The find() method finds the first occurrence of the specified value.

The find() method returns -1 if the value is not found.

txt = "Hello, welcome to my world."

x = txt.find("welcome")

print(x)

Subject | Subject

Some text here about the topic of discussion

13

index() method

The index() method finds the first occurrence of the specified value.

The index() method raises an exception if the value is not found.

The index() method is almost the same as the find() method, the only difference is that the find() method returns -1 if the value is not found.

txt = "Hello, welcome to my world."

x = txt.index("welcome")

print(x)

Subject | Subject

Some text here about the topic of discussion

14

replace() method

The replace() method replaces a specified phrase with another specified phrase.

txt = "I like bananas"

x = txt.replace("bananas", "apples")

print(x)

Subject | Subject

Some text here about the topic of discussion

15

split() method

The split() method splits a string into a list.

You can specify the separator, default separator is any whitespace.

txt = "welcome to the jungle"

x = txt.split()

print(x)

Subject | Subject

Some text here about the topic of discussion

16

upper() method

The upper() method returns a string where all characters are in upper case.

 Symbols and Numbers are ignored.

txt = "Hello my friends"

x = txt.upper()

print(x)

Subject | Subject

Some text here about the topic of discussion

17

lower() method

The lower() method returns a string where all characters are lower case.

 Symbols and Numbers are ignored.

txt = "Hello my FRIENDS"

x = txt.lower()

print(x)

Subject | Subject

Some text here about the topic of discussion

18

format() method

The format() method formats the specified value(s) and insert them inside the string's placeholder. The placeholder is defined using curly brackets: {}.The format() method returns the formatted string.

txt = "For only {price} dollars!"

print(txt.format(price = 49))

Subject | Subject

Some text here about the topic of discussion

19

strip() method

The strip() method removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove)

txt = "     banana     "

x = txt.strip()

print("of all fruits", x, "is my favorite")

Subject | Subject

Some text here about the topic of discussion

20

There are a lot of other string methods. Other methods are listed in the link below.

Some text here about the topic of discussion

21

Fill in the Blank

Question image

Return the string without any whitespace at the beginning or the end.

22

Fill in the Blank

Question image

Convert the value of txt to upper case.

23

Fill in the Blank

Question image

Convert the value of txt to lower case.

24

Fill in the Blank

Question image

Replace the character H with a J. Write the needed words with spaces.

25

Fill in the Blank

Question image

Insert the correct syntax to add a placeholder for the age parameter.

26

Multiple Choice

Which of the following is not a valid string method in Python?

1

upper()

2

lower()

3

middle()

4

strip()

27

Solve string problems

Some text here about the topic of discussion

28

29

30

web page not embeddable

Python | Check if a given string is binary string or not - GeeksforGeeks

You can open this webpage in a new tab.

31

Open Ended

Ask any questions.

32

media

The lesson is over.

List and string methods

By Akniyet Sarsenbek

Show answer

Auto Play

Slide 1 / 32

SLIDE