top of page
Search
Writer's pictureMaia

Python Tips Series: String Padding



In this series, I'll introduce all the cool and bite-size Python tips and tricks that I found very helpful over the time in my data science journey.

I found myself many times searched on Google or Stackoverflow for some small things like how to add string to have a fixed side string in Python, or how to sort a list in python, etc.

There's nothing wrong about searching on the internet for references or knowledge, especially for some technical solutions of something so vast and powerful like Python which always has many solutions for a single problem. And, as most data scientists and developers agree googling is also a very important skill and we shouldn't try to remember anything, just need to know how to google it.

But in my case, as a junior data scientist, I want to try to remember some fundamental knowledge and also some good tips and tricks that I often use. This helps me to retain the things I have learn and done better and also it's more efficient then searching the internet for every little things.

So, I decided to start taking notes of small but very useful pieces of technical solutions or knowledges for some specific repetitive tasks that I regularly encounter in my data science job.

And, today I'll start with a very simple but also super useful tip in Python is using the Python's format function to add leading or tailing spaces (or any character) to a string to have a fixed-wide string.

I think this is a very tiny tip, but I found it is really a neat and useful technique that does the job well in a very Pythonic way.


Happy coding!


Link to source code:

https://github.com/MaiaNgo/python-best-practices/blob/master/string_padding.ipynb

Recent Posts

See All

コメント


Post: Blog2_Post
bottom of page