![]() |
|
[Python] Proper String Formatting - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Proper String Formatting (/showthread.php?tid=5557244) |
Proper String Formatting - (╯°□°)╯︵ ┻━━┻ - Feb 21, 2017 * - SIM-1866423 - Feb 21, 2017 Jump into 3.6 now im fan of f-strings right now, huh wat is wrong with you ! * - (╯°□°)╯︵ ┻━━┻ - Feb 21, 2017 (Feb 21, 2017 01:02 PM)B3mB4m Wrote: Jump into 3.6 now im fan of f-strings right now, huh wat is wrong with you ! Yeah, f-strings look really cool but most of my clients are on 3.5 so anything that I update needs to be compatible. * - Goodies - Feb 21, 2017 I agree. I'm pretty well known on here for being a Python 3 fuckboi, and 3.6 did some great things with asyncio, but when it comes down to writing modules that you want people to use, then writing it for 3.3+ is the best way to go (or at least 3.5 which has been around for a couple of years almost). * - mattdax - Feb 21, 2017 IMO i personally like the commas and + over format(). Just to me it looks so much easier to understand and makes more sense, however I am always open minded if someone cared to explain to me why .format() is better. * - (╯°□°)╯︵ ┻━━┻ - Feb 21, 2017 (Feb 21, 2017 08:24 PM)mattdax Wrote: IMO i personally like the commas and + over format(). Just to me it looks so much easier to understand and makes more sense, however I am always open minded if someone cared to explain to me why .format() is better. Not every object can be concatenated together. If you look at my first example, try doing: Code first_name = "Ron"This one wont error. Code print("Your name is {0} {1} and your age is {2}.".format(first_name, last_name, age))* - mattdax - Feb 21, 2017 (Feb 21, 2017 08:27 PM)(╯°□°)╯︵ ┻━━┻ Wrote: Not every object can be concatenated together. If you look at my first example, try doing: Right, but in that case you could just use commas and you wouldn't need worry about casting. * - (╯°□°)╯︵ ┻━━┻ - Feb 21, 2017 (Feb 21, 2017 08:49 PM)mattdax Wrote: Right, but in that case you could just use commas and you wouldn't need worry about casting. Can you map a dictionary with commas? Or a class? Honestly one of the best features of format(). * - Folks - Feb 22, 2017 (Feb 21, 2017 06:51 PM)Goodies Wrote: I agree. I'm pretty well known on here for being a Python 3 fuckboi, and 3.6 did some great things with asyncio, but when it comes down to writing modules that you want people to use, then writing it for 3.3+ is the best way to go (or at least 3.5 which has been around for a couple of years almost). Nothing wrong with being a python 3 fuckboi, in basic terms, its literally the future of python. * - IChoseDogLeading - Mar 1, 2017 Thanks for that just starting out, this helped a lot * - (╯°□°)╯︵ ┻━━┻ - Mar 1, 2017 (Mar 1, 2017 08:24 PM)IChoseDogLeading Wrote: Thanks for that just starting out, this helped a lot No problem! Anything else you think that would be helpful? I'm currently working on a semi-intermediate subject but I'm trying to explain it in a way that anybody should be able to understand. * - (╯°□°)╯︵ ┻━━┻ - Mar 3, 2017 I've updated it a little bit: http://pythonforalayman.com/string-formatting |