Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele String Indexing in Python | Variables and Types in Python
Introduction to Python(ihor)
course content

Kurssisisältö

Introduction to Python(ihor)

Introduction to Python(ihor)

1. First Acquaintance with Python
2. Variables and Types in Python
3. Conditional Statements in Python
4. Other Data Types in Python
5. Loops in Python
6. Functions in Python

book
String Indexing in Python

To access a specific character in a string, use square brackets with an index number inside. Python uses zero-based indexing, meaning the index number does not correspond directly to the character's position.

12345
# The string of digits word = "codefinity" # Access the character at index 1 (second character) print(word[1])
copy

Negative indexing in Python allows you to access elements from the end. Instead of starting from the beginning (index 0), negative indexing starts from the end (index -1), which represents the last element.

12345
# The string of digits word = "codefinity" # Access the characters at index -1 and -9 (first and last ones) print(word[-1], word[-10])
copy
question mark

Given the string what character is at index [4] and [-8]?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 7
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt