#๐ Range to the negative value
28 messages ยท Page 1 of 1 (latest)
@frail seal
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.
Yeah.
!e
print([i for i in range(0, -2)])
@willow pendant :white_check_mark: Your 3.12 eval job has completed with return code 0.
[]
!e
code
In this case.
Why it didn't print negative distance the same way as positive did?
Since you are incrementing by +1 (it's defaulted this way) nothing is in the list.
!e
print([i for i in range(0, -2, -1)])
@rough bloom :white_check_mark: Your 3.12 eval job has completed with return code 0.
[0, -1]
Oh I see.
yes. thats the 3rd param which for memory is called step. Defaults to 1. Though can make it what you want.
The third value is how many values you want to leap over, yes?
Yes.
If it's not mentioned, it will add 1 by default.
In your case you want -1.
Therefore you must specify.
It works for others too
!e
print([i for i in range(0, 20, 2)])
@willow pendant :white_check_mark: Your 3.12 eval job has completed with return code 0.
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
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.
