Advertisement
ganiyuisholaafeez

Format Method

Feb 19th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # This function is to test the truthiness or falseness of an object
  2. # The function accept one argument
  3. def truthy_or_falsy(value):
  4.  
  5. # Stating the format of the string using the formate method
  6.     string = "The value {0} is {1}"
  7.  
  8.     if value == 0 or "":
  9.         result = string.format(value, "falsy") # the index of value = 0 while falsy = 1
  10.     else:
  11.         result = string.format(value, "truthy") # the index of value = 0 while falsy = 1
  12.  
  13. # Returning the formatted string
  14.     return result
  15.  
  16. # Function Declaration
  17. print(truthy_or_falsy(0))
  18. print(truthy_or_falsy(5))
  19. print(truthy_or_falsy("Hello"))
  20. print(truthy_or_falsy(""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement