Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
28
6
61
10.2K
Jenny
Jenny@JennyTheDev·
@PythonPr B) 5 - integers are immutable in Python, y got the value not the reference
English
1
0
4
656
LearnAIWithMe
LearnAIWithMe@learnwithmeai·
@PythonPr Code: x = 5 y = x x = 10 print(y) Step by step: x is 5 y gets the value of x → y = 5 x changes to 10 y does NOT change So the output is: 5 Correct answer: B) 5
English
0
0
3
256
Prem Prakash
Prem Prakash@4EverPrem·
@PythonPr 5. Python passes values to a variable by object reference. Since y is int, it is immutable, therefore, y is a new object different from x and allocated different memory. Therefore, changes in x does not impact y.
English
0
0
2
407
Taseer Mehboob
Taseer Mehboob@Taseermehboob09·
@PythonPr It's 5 as the value of y will not change by the X down there
English
0
0
0
0
JayRocketMaN
JayRocketMaN@Odidikasomto·
@PythonPr B, because of positional assignment of x to 5 before x to 10
English
0
0
0
14
Paylaş