+ 6
Function returns none by default . print(f'The sum of a and b is {add("all","of you")}') Use double quotes to differentiate it from single quotes .
7th Feb 2021, 10:38 AM
Abhay
Abhay - avatar
+ 8
∆BH∆Y , i would not recommend to print from the function. add() function should only calculate and then return the result. this could be like: # Defining a function add def add(a,b): return a + b # <<<<<<<< #print(a+b) # Calling the function add normally: 1st case print(add(4,7)) # <<<<<<<< # Calling the function add using f strings: 2nd case print (f'The sum of a and b is {add(4,7)}') # Calling the function add usin fstrings, now; concatenation: 3rd case print(f'The sum of a and b is {add("all ","of you")}')
7th Feb 2021, 12:12 PM
Lothar
Lothar - avatar
+ 4
∆BH∆Y """add(4,7) # Calling the function add using f strings: 2nd case print (f'The sum of a and b is {add(4,7)}') """ In the first ,add(4, 7) you aren't printing the actual function but in second one you are doing so .
7th Feb 2021, 10:49 AM
Abhay
Abhay - avatar
+ 3
# input print(print('hello world')) # output hello world None # double print function creates a None always. I guess print(print('hello world')) should produce --> hello world None None ( not sure, we can try it ) So print(add(4,7)) --> print(print(4+7)) --> 11 None
7th Feb 2021, 12:23 PM
Mir Abir Hossain
Mir Abir Hossain - avatar