#๐ I have a problem where everything is random
18 messages ยท Page 1 of 1 (latest)
@broken timber
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.
here is the code
that's not how you use range
did you want to check whether x is 0, 1 or 2?
yes
what you can do is check if x in range(3), remembering that the 3 won't be included due to how range works
that's again not how range works, you just need x in range(3)
ah
!d range
class range(stop)``````py
class range(start, stop[, step])```
The arguments to the range constructor must be integers (either built-in [`int`](https://docs.python.org/3/library/functions.html#int) or any object that implements the [`__index__()`](https://docs.python.org/3/reference/datamodel.html#object.__index__) special method). If the *step* argument is omitted, it defaults to `1`. If the *start* argument is omitted, it defaults to `0`. If *step* is zero, [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) is raised.
For a positive *step*, the contents of a range `r` are determined by the formula `r[i] = start + step*i` where `i >= 0` and `r[i] < stop`.
For a negative *step*, the contents of the range are still determined by the formula `r[i] = start + step*i`, but the constraints are `i >= 0` and `r[i] > stop`.
i did it
example
range(4) -> [0, 1, 2, 3]
range(1, 4) -> [1, 2, 3]
range(0, 4, 2) -> [0, 2]
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.
๐ I have a problem where everything is random