1)----- def do_something(val1): val1 += 1 x = 1 do_something(x) print(x) output: 1 2)---- def do_something(val1):

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

1)----- def do_something(val1): val1 += 1 x = 1 do_something(x) print(x) output: 1 2)---- def do_something(val1):

Post by answerhappygod »

1)-----
def do_something(val1):
val1 += 1
x = 1
do_something(x)
print(x)
output: 1
2)----
def do_something(val1):
val1[0] += 1
x = [1]
do_something(x)
print(x[0])
Output: 2
Can you help explain why first part output is 1 and second part
output is 2?
And how to make first output also become 2?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply