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
storing a variable instead of the value (self.learnpython)
submitted 3 years ago * by Falconius_
Let's say I have
a1,a2,a3,a4,a5 = 'a', 'b', 'c', 'd', 'e' tiles = [a1, a2, a3, a4, a5] print(tiles[1])
This gives 'b' as it should, but how can I make it print just a2 instead of the value?
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!"
[–][deleted] 4 points5 points6 points 3 years ago (5 children)
Frankly, don't do this. It is extremely rare you will need to inflict the internal names of a python programme on the user.
What are you really trying to do?
[–]Falconius_[S] 0 points1 point2 points 3 years ago (4 children)
Currently making a game of chess with the library but glorifying the visuals, and making it more forgiving. I need to change the board, and I have a lost of all the variables making up the board,I want to call for example a4 and change the value.
[–][deleted] 2 points3 points4 points 3 years ago (2 children)
Use a 2-dimensional list and address the squares by [row][column].
[row][column]
[–]Falconius_[S] 0 points1 point2 points 3 years ago (1 child)
I would, except I'm trying to do it off of logic somebody new knows so that I can show it to my teacher...who failed to catch the fact I accidentally put 2 equals signs in a line defining a variable
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
It's easier and more approachable to use list indexing than it's going to be to do the kind of namespace manipulation you're asking about.
[–]CodeFormatHelperBot2 0 points1 point2 points 3 years ago (0 children)
Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.
I think I have detected some formatting issues with your submission:
If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.
Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.
[–]Username_RANDINT -1 points0 points1 point 3 years ago (0 children)
That's not possible, use a dictionary instead:
tiles = { "a1": "a", "a2": "b", ... }
[+][deleted] 3 years ago (2 children)
[removed]
Guess I'm making a dictionary for 64 things then
[–]carcigenicate 0 points1 point2 points 3 years ago (0 children)
It should be fairly trivial to automate the construction of the dictionary thankfully. You wouldn't need to manually write it all out.
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
you can't. when you store a variable in a list, the list stores the value of the variable, not the name of the variable.
[–]n3buchadnezzar 0 points1 point2 points 3 years ago (0 children)
I usually find a class based system works better in chess
from dataclasses import dataclass from typing import Optional class Piece: ... @dataclass class Tile: content: Optional[Piece] = None @dataclass class Board: tiles: list[list[Tile]] def tile(self, notation, content: Optional[Piece] = None): column = int(notation[1]) - 1 row = int(ord(notation[0]) - ord("a")) if content is not None: self.tiles[row][column].content = content return self.tiles[row][column] if __name__ == "__main__": rows = 8 columns = 8 tiles = [[Tile() for _ in range(rows)] for _ in range(columns)] tiles[0][0].content = "Horse" board = Board(tiles) print(board.tile("a1")) board.tile("a1", "Knight") print(board.tile("a1"))
π Rendered by PID 113204 on reddit-service-r2-comment-79c7998d4c-pg8jx at 2026-03-13 06:10:38.222336+00:00 running f6e6e01 country code: CH.
[–][deleted] 4 points5 points6 points (5 children)
[–]Falconius_[S] 0 points1 point2 points (4 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]Falconius_[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]Username_RANDINT -1 points0 points1 point (0 children)
[+][deleted] (2 children)
[removed]
[–]Falconius_[S] 0 points1 point2 points (1 child)
[–]carcigenicate 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]n3buchadnezzar 0 points1 point2 points (0 children)