bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python - Slicing Strings

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Python - Slicing Strings?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

b = "___, World!"
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Specify the start index and the end index, separated by a colon, to return a part of the string.
You can return a range of characters by using the slice syntax.
Slice From the Start

Slicing

You can return a range of characters by using the slice syntax.

Specify the start index and the end index, separated by a colon, to return a part of the string.

Example

b = "Hello, World!"

print(b[2:5])

Note

The first character has index 0.

Slice From the Start

By leaving out the start index, the range will start at the first character:

Example

b = "Hello, World!"

print(b[:5])

Slice To the End

By leaving out the end index, the range will go to the end:

Example

b = "Hello, World!"

print(b[2:])

Negative Indexing

Example

b = "Hello, World!"

print(b[-5:-2])

Previous

Python Strings

Next

Python - Modify Strings