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
38
8
105
13.5K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Answer: C) n Python supports negative indexing. -1 refers to the last element of a sequence. "python" → p y t h o n So: a[-1] → n Negative indexing is often used to access elements from the end of lists, strings, or tuples.
English
1
0
11
1.1K
Jimmy Fikes
Jimmy Fikes@akajim·
@PythonPr C. Negative indexes count backwards from the last element starting with -1, so a[-1] is n.
English
0
0
3
487
Grok
Grok@grok·
Bring Ideas to Life with Grok Imagine
English
0
537
5.5K
11.6M
Victor
Victor@davik4life·
@PythonPr c) n is the correct answer.
English
0
0
1
0
laso
laso@lasitolas·
@PythonPr C ...n take note of the negative index -1
English
0
0
1
292
Mott & Bow
Mott & Bow@MottandBow·
3 reasons why you’ll love our tees: - They hide your belly and man boobs - They’re luxuriously soft - They’re instant compliment magnets
English
140
218
2.8K
10.5M
Mithun deb
Mithun deb@0xmithundeb·
@PythonPr There is no doubt it should be option C. n
English
0
0
0
189
NexaTools
NexaTools@WahabKhan439410·
@PythonPr Negative indexing in Python starts from the end! a[-1] = last character a[-2] = second last a[-3] = third last "python"[-1] = "n" One of Python's coolest features!
English
0
0
0
5
cozy
cozy@Cozy1712·
@PythonPr C, this is because negative indexing start counting from the last element.
English
0
0
0
25
Karathanasis Athanasios
Karathanasis Athanasios@k_athanasi·
@PythonPr C) n last ellement/index in array (-2 whould be o as it goes in reverse ). i always hate that it is -1 and not -0 considering arrays index starts at 0
English
0
0
0
33
Jeff
Jeff@Jeff72571425107·
@PythonPr c) n start at the end of the length of the string -1 and print 1 a = "Python" print(a[-1]) print(a[len(a)-1:len(a):1]) Output: n n
English
0
0
0
38
Xen0risDEV
Xen0risDEV@Xen0risDEV·
@PythonPr C) n a[0] = p a[1] = y a[2] = t a[3] = h a[4] = o a[5] = n a[-1] = n a[-2] = o a[-3] = h a[-4] = t a[-5] = y a[-6] = p
Français
0
0
0
48
Wilson Wizard
Wilson Wizard@ASolovichh·
@PythonPr Indentation is key in Python, so I'm guessing the output will be an indentation error because the code isn't properly indented.
English
0
0
1
347
David Protein
David Protein@david_protein·
David delivers the most protein for the fewest calories. Perfected taste, texture, and macros. Buy 4 cartons on our site, and get the 5th free.
English
0
42
403
840.3K
Paylaş