1languages = ['Python', 'C', 'C++', 'C#', 'Java']
2
3#Bad way
4i = 0 #counter variable
5for language in languages:
6 print(i, language)
7 i+=1
8
9#Good Way
10for i, language in enumerate(languages):
11 print(i, language)
12
1for index,subj in enumerate(subjects):
2 print(index,subj) ## enumerate will fetch the index
3
40 Statistics
51 Artificial intelligence
62 Biology
73 Commerce
84 Science
95 Maths
1for index,char in enumerate("abcdef"):
2 print("{}-->{}".format(index,char))
3
40-->a
51-->b
62-->c
73-->d
84-->e
95-->f
1>>> frutas = ["manzanas", "peras", "naranjas"]
2>>> for i, fruta in enumerate(frutas):
3... print(i, fruta)
40 manzanas
51 peras
62 naranjas
1np.r_[1:10, 15, 17, 50:100]
2
3array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 17, 50, 51, 52, 53, 54, 55,
4 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
5 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
6 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])
7