TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python min() function with Examples

Python min() function with Examples on append(), clear(), extend(), insert(), pop(), remove(), index(), count(), pop(), reverse(), sort(), copy(), all(), bool(), enumerate(), iter(), map(), min(), max(), sum() etc.

<< Back to PYTHON

Python min() Function

Python min() function is used to get the smallest element from the collection. This function takes two arguments, first is a collection of elements and second is key and returns the smallest element from the collection.

Signature

min (collection[, key])

Parameters

collection: It is a comma-separated list of elements.

key: Specifies a one-argument ordering function.

Return

It returns the smallest element from the collection.

Let's see some examples of min() function to understand it's functionality.

Python min() Function Example 1

A simple example to get the smallest element from the collection. See the below example.

# Python min() function example
# Calling function
small = min(2225,325,2025) # returns smallest element
small2 = min(1000.25,2025.35,5625.36,10052.50)
# Displaying result
print(small)
print(small2)

Output:

325
1000.25

Python min() Function Example 2

# Python min() function example
# Calling function
small = min('a','A','b','B') # returns smallest element
small2 = min([10,12],[12,21],[13,15])
# Displaying result
print(small)
print(small2)

Output:

A
[10, 12]

Python min() Function Example 3

# Python min() function example
# Calling function
small = min("Python","Java","Scala") # returns smallest element
small2 = min([10,12,33],[12,21,55],[13,15], key=len) # returns smallest element's length
# Displaying result
print(small)
print(small2)

Output:

Java
[13, 15]

Next TopicPython Functions




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf