they don't hold all the elements in the memory at once. This is an optimization, ranges are generators. Python interpreter is smart enough to convert a slice of range into another range. So you start at 4, and go down by adding -1 until you hit stop, also exclusively. Step is added repeatedly starting from start. Range also has syntax start,stop,step but the step has a different meaning. If you have only start, it returns one element given by the index start. So means from 1st element to last element in steps of 1 in reverse order. Negative number for step means "in reverse order".Negative numbers for start and stop mean "from the end".
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |