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
23
5
71
6.9K
Jimmy Fikes
Jimmy Fikes@akajim·
@PythonPr B. The length of nums (which is the same as vals) is 5. The pop() method decreases 5 to 4. There are two append methods at bring the length up from 4 to 6.
English
0
0
5
355
Theoden
Theoden@J_Theoden·
vals = nums creates a pointer in memory to the same list. So whatever you do to vals is done to nums. So the pop reduces the length to 4. The 2 appends increases the length to 6. So the answer is B: Here is my code which adds a couple of print statements and then adds a "is" test to both lists: nums = [5, 10, 15, 20, 25] vals = nums vals.pop() vals.append(30) vals.append(35) print("Length of nums is : " , len(nums)) print("Vals = :", vals) print("Nums = ", nums) print(vals is nums) Here is the output: Length of nums is : 6 Vals = : [5, 10, 15, 20, 30, 35] Nums = [5, 10, 15, 20, 30, 35] True
English
0
0
2
178
Ifechukwude Nwoko
Ifechukwude Nwoko@IFECHUKWUD37623·
@PythonPr pop removes last element (25) by default append 2more elements print(len()) = 6
English
0
0
2
89
Olatide_enoch
Olatide_enoch@Crafted1638·
@PythonPr B) 6 vals.pop() removes the last element which decreases the len of nums from 5 to 4. Then we have two other numbers appended to the list to make len(nums) = 6
English
0
0
1
100
TIME
TIME@TIME·
At Nvidia's annual GTC conference, CEO Jensen Huang showcased the brands Vera Rubin system, its superchip platform.
English
138
331
3K
7.8M
cozy
cozy@Cozy1712·
@PythonPr B) pop removes the last element of the list 25, then 30 and 35 is now appended. Which makes the list 6
English
0
0
1
103
Starlink
Starlink@Starlink·
Stream. Scroll. Surf. Get speeds up to 400+ Mbps to connect with friends and family without delays.
English
253
713
4.7K
16.7M
Paylaş