1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| >>> tag = '<a href="http://www.python.org">Python web site</a>' >>> tag[9:30] 'http://www.python.org'
>>> tag[32:-4] 'Python web site'
>>> numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> numbers[3:6] [4, 5, 6] >>> numbers[0:1] [1] >>> numbers[7:10] [8, 9, 10]
>>> numbers[-3:-1] [8, 9]
>>> numbers[-3:0] []
>>> numbers[-3:] [8, 9, 10]
>>> numbers[:3] [1, 2, 3]
>>> numbers[:] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> url = input('Please enter the URL:') >>> domain = url[11:-4] >>> print("Domain name: " + domain) Please enter the URL: http://www.python.org Domain name: python
>>> numbers[0:10:1] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> numbers[0:10:2] [1, 3, 5, 7, 9] >>> numbers[3:6:3] [4] >>> numbers[::4] [1, 5, 9]
>>> numbers[8:3:-1] [9, 8, 7, 6, 5] >>> numbers[10:0:-2] [10, 8, 6, 4, 2] >>> numbers[0:10:-2] [] >>> numbers[::-2] [10, 8, 6, 4, 2] >>> numbers[5::-2] [6, 4, 2] >>> numbers[:5:-2] [10, 8]
|