-2

So I tried everything I could and still I have no clue why does it return None Can someone help me?

class TextEditor:
commandCaller = ""
    def text_size(self, word=str, options='upper' or 'lower'):
    try:
        self.commandCaller = 'text_editor()'
        if options.lower() == 'upper':
            updated = '{}'.format(word).upper()
        elif options.lower() == 'lower':
            updated = '{}'.format(word).lower()
        else:
            pass
        print(updated)
    except UnboundLocalError:
        print("You typed something wrong or without a logic")

textEditor = FriendlyLanguage.TextEditor()
textEditor.text_size('hello')

And This is what it returns:

None
HELLO
  • 2
    The function does not explicitly returns anything, and by default Python returns None – abc Sep 17 '20 at 20:54
  • If you invoke the function with `options' as argument, say 'lower'. Does it still not work? It seems like it flows into the else, and therefore updated never initialized. Better solution maybe is to initialize update also in else statement. Or initialize it with default, before all the conditions. – Yossi Levi Sep 17 '20 at 20:55
  • Your indentation is broken, and what the `else` is for? Also, you will get an error if `updated` is undefined. – vmemmap Sep 17 '20 at 20:56

1 Answers1

0

Be default functions in Python always return None unless you add a return statement.

LoneLegend
  • 18
  • 13