could someone answer why min(str) fuction fetching null value in python



0

could someone answer why min(str) fuction fetching null value in python


6 Answer(s)


0

the first line of the help should explain the reasons

 

 

min(...)
    min(iterable[, key=func]) -> value
    min(a, b, c, ...[, key=func]) -> value
    
    With a single iterable argument, return its smallest item.
    With two or more arguments, return the smallest argument.
 


0

I agree Yasar's answer.

var1 = [3]; print(var1, type(var1)); print(min(var1)); print("\n")
var2 = [3,7,-5]; print(var2, type(var2)); print(min(var2)); print("\n")
var3 = (3,); print(var3, type(var3)); print(min(var3)); print("\n")
var4 = (3,7,-5); print(var4, type(var4)); print(min(var4)); print("\n")

var5 = ["a"]; print(var5, type(var5)); print(min(var5)); print("\n")
var6 = ["A", "a", "b", "c"]; print(var6, type(var6)); print(min(var6)); print("\n")
var7 = "a"; print(var7, type(var7)); print(min(var7)); print("\n")
var8 = "A", "a", "b", "c"; print(var8, type(var8)); print(min(var8)); print("\n")

Int = 3; print(min(Int)) # It won't work because integer data type is not an iterable one
Float = 3.5; print(min(Float)) # It won't work because float integer data type  is not an iterable one
Bool = True; print(min(Bool)) # It won't work because Boolean integer data type is not an iterable one

# Iterable is an object which returns iterator
# In data types, 
    # string, list, tuples, dictionaries are iterables
    # int, float, boolean are NOT iterables

# Here the question is, why string is iterable and int/float/Boolean is not iterable?
# Answer is, string is like a concatenation of characters so iterable
# Let’s see an example,
strg = "good"
print(strg[1]) # It returns character "o" from the string
print("Data type is:", type(strg))
print("Please note, length of strg =", len(strg))

 

Hi Shivakant,

        To understand better can you paste the code and results?

        Which version of  Python you are using?

 

 

 


0

Hi Rajavel,

using Python 3.

Below is the string, I think output is null because 'space' is there between the strings and that is showing as minimum output. correct me if wrong.

If we remove space then result is 'c'.

str1 = "good code"
print("Minimum of string: ", min(str1)) 

 

Thanks,

Shivakant


0

Since blank has the lowest value among all the characters you passed so you get blank. if you replace blank with something else such as "}" then you would get "c". can you check it out?

 

 


0

yes, If we use use "}" in place of space then getting "c" as output.

Thanks.


0

Absolutely correct Shivakant and Yasar.