Why Does the Scikit-learn Library use a Trailing Underscore Convention for Attribute Names?

If you’ve used the sklearn library in your own code, you may have realized that all attributes are suffixed with a trailing underscore. Here’s an example for the k-means algorithm: In the second-last line, we used the kmeans attribute cluster_centers_. Why does sklearn library not use the attribute name cluster_centers? ‘The short answer is, the … Read more

How to Convert a Python String to an Int and an Int to a String?

String → Integer: Integer → String: ChrisWhile working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students. To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the … Read more

How to Increase Your Salary as a Python Developer?

Today, many senior coders know that their peers are already earning six figures. Yet, most coders don’t. What are the factors that influence whether someone receives a high Python salary? Set Your Goals The Right Way: It sounds trivial but before you can start to increase your salary as a developer, you have to set … Read more

A List of Lambda Functions? This Python Puzzle May Surprise You…

Guido doesn’t like lambda functions too much. Yet, most large code projects contain a lot of them! (Many coders use lambda functions as GUI callbacks, etc.) In this “Coffee Break Python” email series, we take a pragmatic approach regarding Python code style – living in the “is” rather than in the “should be” world. Can … Read more

Decimal: Python’s Float Trap and How to Solve it

You may know the following surprising code snippet: The following explanation is from the puzzle-based learning Python workbook: This puzzle performs a simple arithmetic computation adding together the float value 0.1. The question seems to be very simple—but as we’ll see in a moment, it’s not simple at all. Your inner voice is wrong. And … Read more

Crazy Python Puzzle (Tuple Confusion)

In this article, you’ll study a beautiful Python puzzle which was created by my friend and co-author Lukas. When I saw this puzzle the first time, I was very lazy about it. I looked at the puzzle and immediately threw my answer into Lukas’ face. It was so obvious… But Lukas kept smiling and I … Read more

Where to Host Your Flask App?

I recently finished the educational Python web app Pythonchecker.com for Python code analysis: Before starting the app, I wondered: what’s the fastest way to set up a Python-based web application? My previous Django-based application was self-hosted on a bare metal machine. This was highly complex, error-prone, and tedious. I had to learn Apache web server … Read more

Your Python Code Sucks

Does your code always follow the PEP standard?Have you ever been criticized for not writing “Pythonic code”? I know I have – especially when I was just starting out with Python a few years ago. This can be frustrating because criticism is not always constructive. Destructive criticism kills any motivation there is left for you … Read more