0

I need little bit explanation on the below code because I confused and don't understand.

t = 40 def sum(t): t+= 20 return t sum(t) print(t)

27th Jun 2021, 8:27 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar
3 odpowiedzi
+ 2
I think, you should print sum(t). After you will understand everything.... print(sum(t))
27th Jun 2021, 8:36 PM
Naveen Rathore
Naveen Rathore - avatar
+ 1
When you pass t to sum function it doesn't changes the value of original t , rather it creates a new variable named t . If you are still confused you should search for mutable and immutable data types in python . t here is a immutable data type.
27th Jun 2021, 9:21 PM
Abhay
Abhay - avatar
+ 1
You have in the function return (t) Then you call the function with sum(t) but without print. So you dont get a output of the function. Try it print(sum(t)) Or change the function Return(t) into print(t)
28th Jun 2021, 4:46 AM
Angela
Angela - avatar