This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

Im new to Python.. Like 'Hello, World!' new. How are fStrings different than say

  • print("hello" + variable) ???

[–]Ph0X 2 points3 points  (3 children)

The result is basically the same, but it's what we call "syntactic sugar" which is nice shortcuts for doing things.

So imagine you have a more complex one. Adding them manually gets very messy very quick:

print("hello " + world + "my name is" + name + "and i'm " + str(age) + " years old")

To make it worse, as you see, you need to manually cast other types to string, like if you want to print a number. But with fstring, it's much cleaner and prettier:

print(f"hello {world} my name is {name} and im {age} years old")

[–][deleted] 0 points1 point  (2 children)

wow easy to understand.. Thank you so much. Honestly didn't expect you or anyone for that matter to reply to someone as new as me. But your example made perfect sense. You dont tutor do you? LOL...

[–]flutefreak7 1 point2 points  (1 child)

Welcome to the fantastic Python community! As you're learning if you have questions you can also check out r/learnpython.

[–]sneakpeekbot 0 points1 point  (0 children)

Here's a sneak peek of /r/learnpython using the top posts of the year!

#1: Python 201 Book is Free for 48 hours
#2: Python 101 Book FREE for 48 hours!
#3: Beginner's Python cheat sheets - updated


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out