Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Indexering en Slicing | Strings
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Gegevenstypen in Python

bookIndexering en Slicing

123
s = "python" print(s[0]) # 'p' (first character) print(s[5]) # 'n' (sixth character)
copy
123
s = "python" print(s[-1]) # 'n' (last character) print(s[-2]) # 'o' (second from the end)
copy
12
s = "python" print(s[10]) # IndexError: string index out of range
copy
12
s = "python" s[0] = 'P' # TypeError: 'str' object does not support item assignment
copy
12345
s = "python" print(s[1:4]) # 'yth' (indices 1,2,3) print(s[:4]) # 'pyth' (start defaults to 0) print(s[3:]) # 'hon' (stop defaults to len(s)) print(s[::2]) # 'pto' (every 2nd character)
copy
12
s = "python" print(s[0:100]) # 'python'
copy
123
s = "python" print(s[-3:]) # 'hon' (last three) print(s[::-1]) # 'nohtyp' (reverse)
copy
Note
Note
question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 2

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

bookIndexering en Slicing

Veeg om het menu te tonen

123
s = "python" print(s[0]) # 'p' (first character) print(s[5]) # 'n' (sixth character)
copy
123
s = "python" print(s[-1]) # 'n' (last character) print(s[-2]) # 'o' (second from the end)
copy
12
s = "python" print(s[10]) # IndexError: string index out of range
copy
12
s = "python" s[0] = 'P' # TypeError: 'str' object does not support item assignment
copy
12345
s = "python" print(s[1:4]) # 'yth' (indices 1,2,3) print(s[:4]) # 'pyth' (start defaults to 0) print(s[3:]) # 'hon' (stop defaults to len(s)) print(s[::2]) # 'pto' (every 2nd character)
copy
12
s = "python" print(s[0:100]) # 'python'
copy
123
s = "python" print(s[-3:]) # 'hon' (last three) print(s[::-1]) # 'nohtyp' (reverse)
copy
Note
Note
question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 2
some-alt