Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Indexing | Strings
Introduction to Python | Mobile-Friendly
course content

Kursinnhold

Introduction to Python | Mobile-Friendly

Introduction to Python | Mobile-Friendly

1. Python Basics
2. Variables
3. Strings

book
Indexing

Suppose we have a string. Now it's time to learn how we can work with it. First, let's learn how to access certain string characters.

Use square brackets with an index inside to access a particular string element. An index is not a position of a specific element since indexing in Python starts from 0. Take a look at the example below.

As you can see, the index in Python is always 1 less than the position. For example, we can get several letters of the word above.

1234
# Initial string site = "codefinity" # Get the letters 'o' and 'y' print(site[1], site[9])
copy
question mark

Suppose you are given the string test (in the code below). Choose the element that has index 5.

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 7

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

course content

Kursinnhold

Introduction to Python | Mobile-Friendly

Introduction to Python | Mobile-Friendly

1. Python Basics
2. Variables
3. Strings

book
Indexing

Suppose we have a string. Now it's time to learn how we can work with it. First, let's learn how to access certain string characters.

Use square brackets with an index inside to access a particular string element. An index is not a position of a specific element since indexing in Python starts from 0. Take a look at the example below.

As you can see, the index in Python is always 1 less than the position. For example, we can get several letters of the word above.

1234
# Initial string site = "codefinity" # Get the letters 'o' and 'y' print(site[1], site[9])
copy
question mark

Suppose you are given the string test (in the code below). Choose the element that has index 5.

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 7
Vi beklager at noe gikk galt. Hva skjedde?
some-alt