numbers = [50, 90, 10, 30, 90, 70] numbers.sort() largest_number = numbers[-1] print(largest_number)
We are getting the largest number in a list using the sort() function here. The sort() method is used to sort the list in ascending and descending order.
In the above code snippet:
1. We are defining a list called numbers that contains multiple integer type values.
2. We are sorting the list using the sort() function in python.
3. Getting the last element of the list using python code and storing it to python variable largest_number.
4. Printing the largest_number variable.
We can also get the largest number from a python list using the max() function. It takes the list as a parameter and returns the largest number from this list.
Below is an example to get the largest number from a list in python.
numbers = [50, 90, 10, 30, 90, 70] largest_num = max(numbers) print(largest_num)