A string is an immutable sequence of characters. Because it is a sequence, it supports the same indexing and slicing rules as lists and tuples, so everything you learned there carries over. s = "Python" has length 6; s[0] is 'P', s[5] and s[-1] are both 'n', and s[6] raises IndexError: string index out of range. Python has no separate character type: indexing a string returns another string of length one. You can loop over a string character by character with for ch in s:, and in tests for a substring, so "th" in s is True.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.