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])
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])
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Geweldig!
Completion tarief verbeterd naar 1.67
String Indexing in Python
Veeg om het menu te tonen
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])
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])
Bedankt voor je feedback!