r/pythontips • • Jan 19 '21

Python3_Specific Python String Formatting - A definitive guide

Last week, I finished blogging about Python Strings.

Alot of topics were covered. But my fav is the String Formatting Guide. It covers 4 different ways of String Formatting nand a comparison of their execution times. Check out the guide here.

66 Upvotes

12 comments sorted by

5

u/rothbart_brb Jan 19 '21

If this could be formatted into a PDF of 1-2 pages, this would make a great cheat sheet document to have tacked up on the wall for occasional glances, or laminated and sitting in a pile for reference. I tend to gather well made cheat sheets. Many look good and don't have great content, or have great content and don't especially look good or use the space well, but when one does both, it's almost like a piece of art. My guess is that most programmers will tend to stick to one or two types of string formatting and won't have them all committed to memory. Nice job!

1

u/pylenin Jan 19 '21

Thanks.

1

u/MrDegausser Jan 19 '21

Second this!

3

u/silentmassimo Jan 19 '21

Pretty useful stuff there -- thanks for sharing :)

1

u/pylenin Jan 19 '21

My pleasure !!

1

u/219jw Jan 19 '21

Thanks for sharing

1

u/pylenin Jan 19 '21

My pleasure !!

1

u/Ritterlichkeit Jan 19 '21

Great work! I appreciate the way you explained each one. Very easy to understand, Thanks!

1

u/pylenin Jan 19 '21

My pleasure

1

u/AussieMazza Jan 20 '21

Thanks mate. Have bookmarked!

1

u/pylenin Jan 20 '21

👍👍

1

u/TM_Quest Jan 22 '21

Great work! The difference between the find method and the index method in Python is something I can never remember.

When writing conditionals, does anyone have a preference between:

if s2.count(s1) == 0:

and

if s2.find(s1) == -1: