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
50
13
169
22.1K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: (B) 4 In Python, lists are zero-indexed, meaning the first element is at index 0, the second at index 1, and so on. x = [7, 4, 9] defines a list named x. The elements are: 7 is at index 0. 4 is at index 1. 9 is at index 2. print(x[1]) accesses and prints the
English
2
0
8
253
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: B) 4 List indices: [7, 4, 9] 0 1 2 x[1] = element at index 1 = 4 For beginners: Python uses 0-based indexing. First element is index 0, second is index 1, etc.
English
0
0
7
781
Siddartha DevOps
Siddartha DevOps@SiddarthaDevops·
@PythonPr this comes under list. Answer is 4 the list in python are Zero-indexed, meaning x(0) is the first elemt (7), so , x(1) is the second element(4), and x(2) is the third elemnt(9)...
English
0
0
2
724
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Output B) 4 — Python lists are 0-indexed, so x[1] is the 2nd element.
English
0
0
1
1.4K
Jenny
Jenny@JennyTheDev·
@PythonPr B) 4 x[1] = second element (0-indexed) The real quiz is remembering that arrays start at 0, not 1. Every programmer's origin story includes this betrayal.
English
0
0
1
796
maniat1k
maniat1k@maniat1kUy·
@PythonPr En Python las listas usan indexación desde 0, así que x[0]=7, x[1]=4 y x[2]=9. Por eso print(x[1]) muestra el segundo elemento de la lista.
Español
0
0
1
166
Soham Gupta
Soham Gupta@SohamGupta84438·
@PythonPr Option B : 4 because index of an array starts with 0 and 4 is at first position
English
0
0
0
89
Himal
Himal@himalbhattaraix·
@PythonPr 4 Index started from 0
English
0
0
0
181
Attraktivo
Attraktivo@bytepirates·
@PythonPr Knowing many languages: Is there one language where the answer is *not* B(4)?
English
0
0
0
14
I-share