In [1]:
s = 'abcde'
In [2]:
print(s[0])
In [3]:
print(s[4])
In [4]:
print(s[-1])
In [5]:
print(s[-5])
In [6]:
# print(s[5])
# IndexError: string index out of range
In [7]:
# print(s[-6])
# IndexError: string index out of range
In [8]:
s = 'abcde'
In [9]:
print(s[1:3])
In [10]:
print(s[:3])
In [11]:
print(s[1:])
In [12]:
print(s[-4:-2])
In [13]:
print(s[:-2])
In [14]:
print(s[-4:])
In [15]:
print(s[3:1])
In [16]:
print(s[3:1] == '')
In [17]:
print(s[-100:100])
In [18]:
print(s[1:4:2])
In [19]:
print(s[::2])
In [20]:
print(s[::3])
In [21]:
print(s[::-1])
In [22]:
print(s[::-2])
In [23]:
s = 'abcdefghi'
In [24]:
print(len(s))
In [25]:
# print(s[len(s) / 2])
# TypeError: string indices must be integers
In [26]:
print(s[len(s) // 2])
In [27]:
print(s[:len(s) // 2])
In [28]:
print(s[len(s) // 2:])
In [29]:
s = 'abcあいう'
In [30]:
print(len(s))
In [31]:
print(s[4])
In [32]:
print(s[1:5])