I've written a script in python to meet some conditions. I've defined if, elif and else block within the script. What I wish my script to do is it will check for the if block if it is not None. However, if it is then it will check for elif block to see if there is something to return otherwise it will go fo the else block.
The problem is I can't make my script check for the elif block; rather, it always checks for either if or else block.
How can I make my script check for the elif block as well?
This is my try:
def get_item(element):
item_info = element
if item_info:
print("executing------------1st one")
return item_info
elif item_info: #can't understand how to rectify this line
#some functionalities here to produce result but no luck and the item_info is still None
print("executing------------2nd one")
item_info = ""
if item_info:
return item_info
else:
#some functionalities here to produce result and finally item_info gets some value
print("executing------------3rd one")
item_info = "efgh"
if item_info:
return item_info
if __name__ == '__main__':
something = ""
print(get_item(something))
Aucun commentaire:
Enregistrer un commentaire