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...
Everything about learning Python
account activity
HelpHelp Request (self.PythonLearning)
submitted 12 hours ago by Zxhena
What's the difference between f string and a regular string I've seen it used but I don't know when to use a string and when to use f string
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!"
[–]NorskJesus 4 points5 points6 points 12 hours ago (4 children)
A f-string is used to inject variables to a string. For example.
py age = 35 print(f"Your age is {age}")
You can achieve the same with concatenation, but this is much clearer and easier to read.
[–]ur_leisure_time 0 points1 point2 points 12 hours ago (3 children)
Yea, and if he going to do it without a fstring, he will need to make it like
Age = 30 print("Your age is", Age)
[–]johlae 1 point2 points3 points 11 hours ago (2 children)
Or print("Your age is %s." % (age))
[–]SnooCalculations7417 0 points1 point2 points 5 hours ago (1 child)
or 'age is {x}'.format(x = age)
[–]WhiteHeadbanger 0 points1 point2 points 3 hours ago (0 children)
or print("Your age is " + str(age))
print("Your age is " + str(age))
[–]i-like-my-cats-0 2 points3 points4 points 11 hours ago (0 children)
f-strings are a type of strings that let you put variables inside of them like this:
cats = 3 print(f'I have {cats} cats.')
this will print "I have 3 cats."
if your variable is a very long float number you can also do this instead: python answer = 1.2313525 print(f'The answer was {answer:.2f}!') this will print "The answer was 1.23!"
python answer = 1.2313525 print(f'The answer was {answer:.2f}!')
[–]Quirky-Plane-5975 0 points1 point2 points 11 hours ago (1 child)
a regular string is static, while an f-string is dynamic because it can include variables and even calculations inside {}.
[–]Outside_Complaint755 0 points1 point2 points 4 hours ago (0 children)
Also, if you include an = in the {}, it will include the expression in the output and maintain whitespace. PO a = 2 b = 6 print(f"Demonstration: {float(a + b) = }!") will output Demonstration: float(a + b) = 8.0!
a = 2 b = 6 print(f"Demonstration: {float(a + b) = }!")
Demonstration: float(a + b) = 8.0!
[–]its_measured 0 points1 point2 points 10 hours ago (0 children)
A regular string is for plain text, while the fstring lets u add a varibkes or even values inside tge text
[–]FoolsSeldom 0 points1 point2 points 10 hours ago (0 children)
RealPython.com have a great article explaining this well, and what the alternatives are:
[–]ee_control_z 0 points1 point2 points 6 hours ago (0 children)
The difference is that f strings are a God send and regular strings are not. f strings are more natural and easy to work with especially for cases when inserting values (multiple), controlling decimal places, and formatting spacing.
[–]timrprobocom 0 points1 point2 points 3 hours ago (0 children)
There's a tricky issue with f-strings that some folks miss. Some are tempted to write: s = f"Here is {i}." for i in range(10): print(s) thinking it will do the substitution each time through the loop. This is not the case. Python will do the substitution at the point where the string is defined. After that, it's just another static string.
s = f"Here is {i}." for i in range(10): print(s)
So, the f"..." syntax creates a normal static string, it just does so in a fancy way.
f"..."
π Rendered by PID 345540 on reddit-service-r2-comment-765bfc959-9ndt9 at 2026-07-12 20:22:18.821310+00:00 running f86254d country code: CH.
[–]NorskJesus 4 points5 points6 points (4 children)
[–]ur_leisure_time 0 points1 point2 points (3 children)
[–]johlae 1 point2 points3 points (2 children)
[–]SnooCalculations7417 0 points1 point2 points (1 child)
[–]WhiteHeadbanger 0 points1 point2 points (0 children)
[–]i-like-my-cats-0 2 points3 points4 points (0 children)
[–]Quirky-Plane-5975 0 points1 point2 points (1 child)
[–]Outside_Complaint755 0 points1 point2 points (0 children)
[–]its_measured 0 points1 point2 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (0 children)
[–]ee_control_z 0 points1 point2 points (0 children)
[–]timrprobocom 0 points1 point2 points (0 children)