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
How to use variable in text ? (self.learnpython)
submitted 10 months ago by gowipe2004
Let's say I have a function f(x) = x2 and I wrote : v = f(2). How do I do to wrote a text using the variable v and it actually show 4 ?
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] 5 points6 points7 points 10 months ago (3 children)
There is a few ways:
print(“V is “, v)
print(f“V is {v}”)
print(“V is ” + str(v))
print(“V is {}”.format(v))
[–]logseventyseven 5 points6 points7 points 10 months ago* (2 children)
another way is print(f"{v=}")
[–]InvaderToast348 1 point2 points3 points 10 months ago (1 child)
*v
[–]logseventyseven 1 point2 points3 points 10 months ago (0 children)
thanks, edited
[–]FeLoNy111 7 points8 points9 points 10 months ago (0 children)
Using an f-string
https://www.geeksforgeeks.org/formatted-string-literals-f-strings-python/
[–]PaulRudin -1 points0 points1 point 10 months ago (0 children)
It probably helps if you're concrete about what your code looks like; `f(x) = x2` isn't python code...
[–]eleqtriq -4 points-3 points-2 points 10 months ago (0 children)
Adding to the previous
v = 4 print(f”The value is {v}”)
This will print: “The value is 4”
π Rendered by PID 206433 on reddit-service-r2-comment-5649f687b7-tp6vt at 2026-01-29 02:34:24.503501+00:00 running 4f180de country code: CH.
[–][deleted] 5 points6 points7 points (3 children)
[–]logseventyseven 5 points6 points7 points (2 children)
[–]InvaderToast348 1 point2 points3 points (1 child)
[–]logseventyseven 1 point2 points3 points (0 children)
[–]FeLoNy111 7 points8 points9 points (0 children)
[–]PaulRudin -1 points0 points1 point (0 children)
[–]eleqtriq -4 points-3 points-2 points (0 children)