Search code examples
if-statementdefinition

Use of conditional function, condition in definition


I have a seemingly trivial problem. I write a definition and I don't know how to introduce conditional functions.

I have a definition that works:

def function_1 (kot):
     if kot == True:
         print ("Yes:")
     else:
         print ("NO:")

It wokrs good

function_1 (False)

No:

or

function_1 (True)

Yes:

But I would like to have such a thing in my definition

def function_1 (kot = True):
     if kot == True:
         print ("Yes:")
     else:
         print ("NO:")

and it doesn't work any more.


Solution

  • Because you need to call the function as you did in the above example

    def function_1 (kot=True):
     if kot == True:
         print ("Yes:")
     else:
         print ("NO:")
    
    function_1()
    

    output:

    Yes: