Python List min() MethodAdvertisements Previous Page Next Page sort() methodThe sort() method is a built-in Python method that, by default, sorts the list in ascending order. However, you can modify the order from ascending to descending by specifying the sorting criteria. Show ExampleLet's say you want to sort the element in prices in ascending order. You would type prices followed by a . (period) followed by the method name, i.e., sort including the parentheses. prices = [238.11, 237.81, 238.91] prices.sort() print(prices) [237.81, 238.11, 238.91]type() functionFor the type() function, it returns the class type of an object. ExampleHere we will see what type of both fam and fam2 are: fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89] fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89]Let's see what the type of the object is: type(fam) listNow, let's look at fam2. fam2 = [["liz", 1.73], ["emma", 1.68], ["mom", 1.71], ["dad", 1.89]] fam2 [['liz', 1.73], ['emma', 1.68], ['mom', 1.71], ['dad', 1.89]]Let's see what the type of the object is: type(fam2) listThese calls show that both fam and fam2 are in fact lists. append() methodThe append() method will add certain content you enter to the end of the elements you select. ExampleIn this example, let’s extend the string by adding “April” to the list with the method append(). Using append() will increase the length of the list by 1. months = ['January', 'February', 'March'] months.append('April') print(months)When you run the above code, it produces the following result: ['January', 'February', 'March', 'April']Python min()In this tutorial, we will learn about the Python min() function with the help of examples. The min() function returns the smallest item in an iterable. It can also be used to find the smallest item between two or more parameters. Examplenumbers = [9, 34, 11, -4, 27]# find the smallest number
min_number = min(numbers)
print(min_number)
# Output: -4The min() function has two forms: # to find the smallest item in an iterable min(iterable, *iterables, key, default) # to find the smallest item between two or more objects min(arg1, arg2, *args, key)Python | Maximum and minimum element’s position in a listGiven a list of N integers, find the maximum and minimum element’s position in the list. Examples: List Methods in Python | Set 1 (in, not in, len(), min(), max()…)List basics have been covered in python in the set below List methods are discussed in this articles. Python3
Output: List is having element with value 4 List is having element with value 43. len() :- This function returns the length of list. Python3
Output: The length of list is : 5 The minimum element of list is : 1 The maximum element of list is : 5 6. “+” operator :- This operator is used to concatenate two lists into a single list. Python3
Output: list after concatenation is : 1 2 3 4 5 6 list after combining is : 1 2 3 1 2 3 1 2 38. index(ele, beg, end) :- This function returns the index of first occurrence of element after beg and before end. Python3
Output: The first occurrence of 3 after 3rd position is : 5 The number of occurrences of 3 is : 2Related articles: This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks. Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics. To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Article Tags :
Python School Programming
python-list python-list-functions Practice Tags :
python-list |