Skip to content
Snippets Groups Projects
Commit 6156bd22 authored by Minseong Kwon's avatar Minseong Kwon
Browse files

Upload New File 문자열 인덱싱과 슬라이싱

parent 6de41732
No related branches found
No related tags found
No related merge requests found
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> #문자열 인덱싱과 슬라이싱
>>>
>>> a="life is too short"
>>> a[0]
'l'
>>> a[3]
'e'
>>> a[2]
'f'
>>>
>>> a[9]
'o'
>>> a[10]
'o'
>>> a[8]
't'
>>> a[11]
' '
>>> a[12]
's'
>>> a[13]
'h'
>>> a[15]
'r'
>>> a[16]
't'
>>> a[17]
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
a[17]
IndexError: string index out of range
>>> a[16]
't'
>>> len(a)
17
>>> a[-1]
't'
>>> a[-2]
'r'
>>> a[-0]
'l'
>>> b=a[0]+a[1]+a[2]+a[3]
>>> b
'life'
>>> a[0:4]
'life'
>>> a[0:3]
'lif'
>>> a[0:5]
'life '
>>> a[0:]
'life is too short'
>>> a[:17]
'life is too short'
>>> a[:16]
'life is too shor'
>>> a[:18]
'life is too short'
>>> a[:100]
'life is too short'
>>> a[1:18]
'ife is too short'
>>> a[1:100]
'ife is too short'
>>> a[18]
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
a[18]
IndexError: string index out of range
>>> a[17]
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
a[17]
IndexError: string index out of range
>>> a[16]
't'
>>> a[2:-2]
'fe is too sho'
>>> a[5:-2]
'is too sho'
>>> a[-1]
't'
>>> a[-3]
'o'
>>> a[-2]
'r'
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment