slice()
In [2]:
###### 0123456789012345678901234567890123456789012345678901234567890'
record = '....................100 .......513.25 ..........'
cost = int(record[20:32]) * float(record[40:48])
print(cost)
In [4]:
SHARES = slice(20,32)
PRICE = slice(40,48)
cost = int(record[SHARES]) * float(record[PRICE])
print(cost)
In [5]:
a = slice(10, 50, 2)
print(a.start)
print(a.stop)
print(a.step)
indices(size)
method.
In [15]:
s = 'HelloWorld'
a = slice(5, 10, 2)
a.indices(len(s))
Out[15]:
In [16]:
for i in range(*a.indices(len(s))):
print(s[i])