Python - String min() method Last Updated : 30 Dec, 2024 Comments Improve Suggest changes Like Article Like Report The min() function in Python is a built-in function that returns the smallest item in an iterable or the smallest of two or more arguments. When applied to strings, it returns the smallest character (based on ASCII values) from the string.Let's start with a simple example to understand how min() works with strings: Python a = "hello" smallest_char = min(a) print(smallest_char) Outpute Explanation:The string "hello" contains the characters: 'h', 'e', 'l', 'l', 'o'.'The min() function finds the smallest character based on ASCII values.The ASCII value of 'e' is smaller than that of 'h', 'l', or 'o', so 'e' is returned.Table of ContentSyntax of min() methodExamples of min() methodFrequently Asked Questions (FAQs)Syntax of min() methodmin(iterable)Parametersiterable: An iterable object (e.g., a string, list, or tuple) from which the smallest element is to be found.Return TypeReturns the smallest element of the iterable based on their ASCII or natural ordering.Raises a ValueError if the iterable is empty.Examples of min() method1. Finding the smallest character in a stringTo find the smallest character in a string is the most widely used example of min() method. Let's see how this works: Python a = "python" smallest = min(a) print(smallest) Outputh Explanation:The min() function scans through these characters and finds 'h', which has the smallest ASCII value.2. Using min() with case sensitivityThe min() function is case-sensitive and considers uppercase letters to have lower ASCII values than lowercase letters. Python a = "HelloWorld" smallest = min(a) print(smallest) OutputH Explanation:The string "HelloWorld" contains both uppercase and lowercase letters.ASCII values: 'H' has an ASCII value of 72, while lowercase letters like 'e' or 'o' have higher ASCII values.Thus, 'H' is returned.3. Applying min() to substringsThe min() function can also be applied to slices of strings. Python s = "PythonProgramming" # Analyzing "Programming" smallest = min(s[6:]) print(smallest) OutputP Explanation:The slice s[6:] extracts the substring "Programming".The smallest character based on ASCII values in "Programming" is 'P'. Comment More infoAdvertise with us Next Article Company Preparation S Striver Follow Improve Article Tags : Misc Python python-string Practice Tags : Miscpython Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like