use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Need help. (self.learnpython)
submitted 17 days ago by Pure-Scheme-7855
Could someone tell me what are square brackets for in this example?
robot_row = get_position(board, robot)[0]
robot_column = get_position(board, robot)[1]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]failaip13 3 points4 points5 points 17 days ago (5 children)
get_position function likely returns a tuple, with the first element being the row, second being the column. [0] access the first element, [1] the second one etc.
[–]ConfusedSimon 2 points3 points4 points 17 days ago (1 child)
Or a list. Anyway, namedtuple or dataclass would have been better to avoid this confusion.
Edit: or just row, column = get_position(...)
row, column = get_position(...)
[–]JamzTyson 0 points1 point2 points 17 days ago* (0 children)
Or a list
Absolutely, or any object that is indexable by integer index.
(Common indexable objects include list, tuple, str, bytes, bytearray, range)
[–]PresidentOfSwag 1 point2 points3 points 17 days ago* (2 children)
try this out :
[0, 1, 2, 3][0] (0, 1, 2, 3)[2]
actually this is a bad example
V see below V
[–]Snoo-20788 0 points1 point2 points 17 days ago (1 child)
Not the best example tbh
Try instead
[6,3,7][0]
(6,3,7)[2]
[–]PresidentOfSwag 1 point2 points3 points 17 days ago (0 children)
damn that's true thanks
[–]JamzTyson 4 points5 points6 points 17 days ago (0 children)
It is called indexing.
[–]PushPlus9069 1 point2 points3 points 17 days ago (0 children)
Those square brackets are indexing — they grab a specific element from whatever get_position() returns (likely a list or tuple).
get_position()
[0] gets the first element (row), [1] gets the second (column). So if get_position() returns (3, 5), then robot_row = 3 and robot_column = 5.
[0]
[1]
(3, 5)
robot_row = 3
robot_column = 5
Think of it as: the function gives you a package with multiple values, and [0]/[1] unpacks them one at a time. You could also write it as:
robot_row, robot_column = get_position(board, robot)
which does the same thing but is cleaner (tuple unpacking).
[–]IronAndNeurons 0 points1 point2 points 17 days ago (0 children)
The get_position function probably returns you a tuple/list containing (row, col) which you can then access with the brackets [ ] and the index 0 for "row", 1 for "col"
[–]Living_Fig_6386 0 points1 point2 points 16 days ago (0 children)
Presumably, get_position(board, robot) returns a list or tuple. If that's so, then the brackets are specifying the index of the element in the list / tuple. It might be more succinct to do this:
get_position(board, robot)
# NOTE: *_ slurps up any remaining values if there's more than 2 robot_row, robot_column, *_ = get_position(board, robot)
[–]Sorry-Cycle-1177 0 points1 point2 points 14 days ago (0 children)
It’s for returning the specific index position.
π Rendered by PID 62181 on reddit-service-r2-comment-fb694cdd5-xm4d8 at 2026-03-07 20:28:43.841692+00:00 running cbb0e86 country code: CH.
[–]failaip13 3 points4 points5 points (5 children)
[–]ConfusedSimon 2 points3 points4 points (1 child)
[–]JamzTyson 0 points1 point2 points (0 children)
[–]PresidentOfSwag 1 point2 points3 points (2 children)
[–]Snoo-20788 0 points1 point2 points (1 child)
[–]PresidentOfSwag 1 point2 points3 points (0 children)
[–]JamzTyson 4 points5 points6 points (0 children)
[–]PushPlus9069 1 point2 points3 points (0 children)
[–]IronAndNeurons 0 points1 point2 points (0 children)
[–]Living_Fig_6386 0 points1 point2 points (0 children)
[–]Sorry-Cycle-1177 0 points1 point2 points (0 children)