#๐ WHY DOES THE 2ND CODE not output '1'
11 messages ยท Page 1 of 1 (latest)
@timber cairn
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
indices start at 0
Because list indexing in python starts at 0, that means list[1] refers to the 2nd element in a list.
@placid hill@dapper estuary what is the difference between print(j) and print (n[j])
print(j) prints the value of the variable j. That can be whatever, an integer, a string, a list ...
print(n[j]) prints the value of whatever is in the list n at position j. That can also be whatever (str, list, int, ...) but j has to be an integer (a whole number).
Thanks
!e
n = [1, 2, 3, 4, 5, 6]
print(n)
for j in range(6):
print(f"j: {j}, n[j]: {n[j]}")```
to visualize this
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | [1, 2, 3, 4, 5, 6]
002 | j: 0, n[j]: 1
003 | j: 1, n[j]: 2
004 | j: 2, n[j]: 3
005 | j: 3, n[j]: 4
006 | j: 4, n[j]: 5
007 | j: 5, n[j]: 6
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.