Introduction In Python, the datetime module can be used to get date and time. This is good but there is something annoying: the milliseconds or the fraction that gets printed by default. How can we get rid of that ? There are a couple of ways to do the trick. Let us see… Example code
Introduction If you skim through Python source code, you may encounter some strings proceeded by a special character such as (b, u). What are these characters? Let us see… The b string prefix The b string prefix in Python 3.x indicates that the string is of type byte stream. If the prefix is not used,
Introduction I think the reason why this topic can be confusing specially to beginners is that it mixes different concepts together. It should not be hard to understand with proper context. In my opinion, to better understand the difference between Args and Kwargs in Python, the following points must be crystal clear… Positional vs keyword
Introduction For more information about for loops in Python, you can find the full article here. So what is the difference between break, continue and pass in Python ? let us borrow some relevant sections from the previous article… Break statement Python like other languages provides a special purpose statement called break. This statement terminates
Introduction In this tiny Python code snippet article, I am going to borrow from the full article about the topic that you can find here. So, what is the difference between bytes and bytearray in Python ? There is no real difference between byte strings and byte arrays except the fact that byte strings are
Introduction So you are curious to know the key difference between a list and tuple in Python ? You can find the answer in many places on the web, however in this code snippet we will summarize it so that it is easy to remember. Take a look at the following table… List vs Tuple
Introduction On the surface, this question looks innocent but if we dig a bit deeper, things start to get confusing. In this short post, we will provide a summary of differences, however to better understand the topic, I recommend that you check the full article here. Depending on which version of Python we are using
Introduction Welcome to a new Python code snippets post. Below, you can find a summary of helpful Python syntax for that purpose… Let us now take some examples… Sorted dictionary keys This will print… Sorted dictionary values This will print… Sorted dictionary items by value This will print… Sorting in reverse order This will print…
Introduction This is a frequently asked question in Python. In this article, I will only provide a short summary. For more details, you may refer to the full article here. So what is the deal about the yield keyword in Python ? The yield keyword in Python has to do with generator functions. Let us
Problem In this Python code snippet, we are going to implement a naive run length encoding algorithm to compress strings Solution The idea is very simple, text has redundancy so instead of sending plain text, we can compress text by sending characters and their counts. This is a typical text processing problem that gets asked