I've just started learning python, and since there are different ways to write the same thing, I was wondering if some ways were more efficient than other. For example, I've written two versions of this super basic code that will print the longest of 3 words; is one of the two versions more efficient than the other? Thank you.
#print the longest word 1
def long_word (word1,word2,word3):
if word1.__len__() > word2.__len__() and word1.__len__()>word3.__len__():
print ("the longest word is" + word1)
elif word2.__len__() >word1.__len__() and word1.__len__()()>word3.__len__():
print ("the longest word is" +word2)
elif word3.__len__() >word1.__len__() and word3.__len__() > word2.__len__():
print ("the longest word is" +word3)
input1=input ("Write 3 words; I will print the longest word. Word 1: ")
input2=input ("Word 2:")
input3=input ("Word 3:")
long_word(input1, input2,input3)
#print the longest word 2
def long_word (word1,word2,word3):
word1a=(len(word1))
word2a=(len(word2))
word3a=(len(word3))
if word1a > word2a and word1a>word3a:
print ("the longest word is" + word1)
elif word2a >word1a and word1a>word3a:
print ("the longest word is" +word2)
elif word3a >word1a and word3a > word2a:
print ("the longest word is" +word3)
input1=input ("Write 3 words; I will print the longest word. Word 1: ")
input2=input ("Word 2:")
input3=input ("Word 3:")
long_word(input1, input2,input3)