Advertisement
nher1625

conditional_function_definition_loop

Jun 8th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. # def executes at runtime
  2. # in python theres is no such thing as a separate compile time.
  3. # because of this def is a truly executable statement and can
  4. # be embedded within conditional statements.
  5. # ex:
  6. trigger = True
  7. while(trigger):
  8.     makeFunc = eval(input("Enter 0 or 1 to define function: "))
  9.     if makeFunc == 0 or makeFunc == 1:
  10.         trigger = False
  11.         break
  12.     else:
  13.         print("Invalid input")
  14.  
  15. if makeFunc == 0:
  16.     def function(x=1,y=2,z=3):
  17.         return None
  18. else:
  19.     def function(x="one",y="two",z="three"):
  20.         return True
  21.  
  22. x = function.__defaults__
  23. print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement