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
42
18
161
15.9K
Sergei Kotov
Sergei Kotov@kotov_dev·
Answer: B (y). my_list[1] accesses index 1, which is 'y'. For beginners: Python uses ZERO-BASED indexing. Index 0='p', Index 1='y', Index 2='t', etc. my_list[1] gives the SECOND element, not the first!
English
0
0
0
272
A  H
A H@habdir·
@PythonPr The way it’s written will out put error, so C is the right answer. If there was indentation B would have been correct.
English
0
0
0
337
Jaysus Daniels
Jaysus Daniels@TheHogDen1932·
@PythonPr B. It’s common for a beginner to mistake the first character in a list as the first index. However, lists in Python are 0-indexed, meaning the first character is at index 0, so in this case, index 1 is ‘y’.
English
0
0
0
557
Joe
Joe@Joe46791334·
@PythonPr B Python indexing starts at 0.
English
0
0
0
10
laso
laso@lasitolas·
@PythonPr B.. slicing of list. Uses index 1 ...remember it starts at 0
English
0
0
0
21
Arun Kumar Singh
Arun Kumar Singh@arunkinsights·
@PythonPr In Python, list indexing starts from 0. my_list[0] → 'p' my_list[1] → 'y' So the output is y. Correct answer: B (y)
English
0
0
0
19
Paylaş