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
25
11
104
9.1K
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: A) [] The trap: Slicing goes start to stop by step (+1 default) › Start 3 > stop 1 › Step +1 = forward › Can't move forward to earlier index so result is [] For beginners: Use negative step when start > stop. Result is in reverse order! nums[3:1:-1] = [6, 5]
English
0
0
11
709
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Answer: A → [] In slicing, if the start index is greater than the end index (and no negative step is given), Python returns an empty list. Here nums[3:1] moves forward by default, so nothing is selected.
English
0
0
9
505
EVY TECHNO
EVY TECHNO@EvyTechno·
Answer: A. [] Syntax: list[start:stop] It returns elements from index start up to but not including stop. If start >= stop and no step is specified, the slice returns an empty list. Here: nums[3:1] start = 3, stop = 1 Since 3 > 1, slicing from index 3 to 1 moves forward but stop is behind start. No negative step is specified, so default is +1, which goes forward. Because start is after stop, slice is empty. Summary: Forward slicing with start > stop returns an empty list. x.com/EvyTechno/stat…
English
0
0
2
488
The root of infinity
The root of infinity@parth_hirpara05·
@PythonPr Start index = 3 End index = 1 Since 3 > 1 and no negative step is given, Python returns an empty list. Ans---> []
English
0
0
2
125
ANKIT 𓃱
ANKIT 𓃱@A9kitSingh·
@PythonPr Answer is A) [] nums[3:1] has start > stop with a positive step, so the slice is empty.
English
0
0
2
105
Pizzy
Pizzy@Pizzy44109·
@PythonPr I have alot to understand
English
1
0
2
63
Laxman 🧮🐧
Laxman 🧮🐧@CodeWithBinary·
@PythonPr answer: [] why: list slicing works only when: 1. start > end 2. step is positive
English
0
0
1
221
Python Tech
Python Tech@PythonTech43716·
@PythonPr A ) [] is the right answer. Here we are using concept of list slicing. [Start:end: step_size] , here step size is not mentioned and default step size is 1 so no output will come. It will return empty string.
English
0
0
1
117
Siddartha DevOps
Siddartha DevOps@SiddarthaDevops·
@PythonPr A. []. since slicing goes forward, nums[3:1] means “start at index 3 and go forward until index 1” → impossible. So the output is []
English
0
0
1
164
Sixtus Agbakwuru
Sixtus Agbakwuru@SixtusAgbakwuru·
@PythonPr The correct answer isbA. [] ✅ Python list slicing [start:stop] goes from start up to but not including stop. Here, start=3 and stop=1. You cannot go from index 3 to index 1 moving forward, so the result is an empty list [].
English
0
0
0
258
Divyank Kumar
Divyank Kumar@divyankk92·
@PythonPr Empty list Bcz List slicing [start:stop]. Here [3:1] here 3 is included but 1 is not thats why result will empty list
English
0
0
0
63
Adedayo Adebayo
Adedayo Adebayo@AdebayoAde40439·
@PythonPr [] If the starting index is greater that the "end" index, you get an empty slice
English
0
0
0
7
Jenny
Jenny@JennyTheDev·
@PythonPr A. [] nums[3:1] means start at index 3, stop at index 1 You can't go backwards with default step. Empty list
English
0
0
0
231
Nikhil | Data Analytics
Nikhil | Data Analytics@nikku762·
@PythonPr Option A – [] Because start index (3) is greater than end index (1) with a positive step, so it returns an empty list.
English
0
0
0
8
Ranjan
Ranjan@Ranjanrgdev·
@PythonPr A. [] We can't move backward in positive indexing
English
0
0
0
14
Paylaş