
Be sure to like, share and comment to show your support for our tutorials. ======================================= Channel - https://goo.gl/pnKLqE Playlist For This Tutorial - https://goo.gl/EyZFti Latest Video - https://goo.gl/atWRkF Facebook - https://www.facebook.com/mastercodeon... Twitter - https://twitter.com/mastercodeonlin?l... Website - http://mastercode.online ====================================== Extending List Function With Range Function In the previous Python tutorial, we learned about the list built-in function in this tutorial we are going to look at extending the list function with range function. List function converts our provided argument into a list object using the range function with the list function not only speeds up writing numbers that are in a sequence but make it a whole lot easier. For example, say we needed a list of numbers between 0 and 20 for our program it would be easier to write using the list function with range function being the argument. Using the range function on list function, we would be returned a list that contained the numbers 0 thru 20. List Function With Range Function Syntax list(range(start, stop, step)) list() - The list function converts our argument into a list object. range() - The range function will provide us with a sequence of numbers. start - This is the starting argument. Whichever number we provide here is where the range function will start listing its numbers in a sequence. stop -This is the stopping argument. This argument shows where we would like our range to stop. For example, if we provide 10 as our stopping number the list will actually stop on 9. This is like slicing the stop number always ends one number before you indicate. step - This is the stepping argument. Which will skip the number by the number provided. Examples Of The List Function with Range Function Example With Stop Argument list(range(4)) [0, 1, 2, 3] Example Explained list(range(4)) - We create a list function that takes the range function as an argument. We provide one argument to the range function. When we provide one argument to the range function the list will count up from zero to the number we include in the range function. In this case, we provide the number four as an argument so we will get a list from 0 to 4. [0, 1, 2, 3] - We are returned a list object that contains the numbers 0 thru 3. Example With Start and Stop Argument list(range(0, 5)) [0, 1, 2, 3, 4] Example Explained list(range(0, 5)) - In this example we include a starting point and ending point for range. [0, 1, 2, 3, 4] - We are returned a range numbers from 0 and 4. Example With Stepping list(range(0, 11, 2)) [0, 2, 4, 6, 8, 10] list(range(0, 11, 2)) - In this example we call range as an argument on the list function and provide a stepping argument. The stepping argument indicates how many numbers do we want to count by. [0, 2, 4, 6, 8, 10] - We are returned a list of numbers that count by 2. Conclusion In this tutorial we looked at extending list function with range function. If you have any questions about the list function or range function leave a comment below.
Extend List Function With Range Function - YouTube |
19 Likes | 19 Dislikes |
2,160 views views | 14,790 followers |
Education | Upload TimePublished on 27 Oct 2015 |
python tutorials point,python tutorials pdf,python tutorials point pdf,python tutorials for beginners,python tutorials advanced,python tutorials video,python tutorials best,python tutorials opencv,python tutorials django,python tutorials basic,python tutorials gui,python tutorialspoint list,python tutorialspoint regex,python tutorialspoint tkinter,python tutorials for beginners pdf,python tutorials youtube,python tutorials online,python tutorials w3schools,tutorialspoint python class,tutorials python 3
Không có nhận xét nào:
Đăng nhận xét