+ 3

How does it give shortest string?

def short_string(x,y): if Len(x)<=Len(y): return x else: return y print(short_string("Manish","Ravi"))

27th Feb 2017, 7:13 AM
Akash
Akash - avatar
7 Answers
+ 5
def shortest_string(x, y): if len(x) <= len (y): return x else: return y
16th Feb 2020, 4:06 AM
Prabu S
Prabu S - avatar
+ 4
In point with strings "len" function returns number of chars in string. If one string contains more characters than second, you will get first.
27th Feb 2017, 7:55 AM
Tony Loa
Tony  Loa - avatar
0
def shortest_string(x, y): if len(x) <= len (y): return x else: return y
8th Jan 2021, 1:53 PM
Kenane Khalil
Kenane Khalil - avatar
0
len return return
11th Feb 2021, 5:58 PM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar
0
len (y): return x else: return y
24th May 2021, 11:05 AM
Hayder Jawad Al-ATBEE
Hayder Jawad Al-ATBEE - avatar
0
def shortest_string(x, y): if len(x) <= len(y): return x else: return y
22nd Sep 2022, 9:37 AM
ABDUL WAHAB
0
def shortest_string(x, y): if len(x) <= len(y): return x else: return y
21st Mar 2023, 8:37 AM
Ű§Ù„Ù…Ù‡Ù†ŰŻŰł ŰŁŰ­Ù…ŰŻ
Ű§Ù„Ù…Ù‡Ù†ŰŻŰł ŰŁŰ­Ù…ŰŻ - avatar