How to Access an Object Attribute Given the Attribute Name as a String?

You may know the following problem: You have an object’s attribute name as a string—say, you’ve read it from a file—and you want to access the attribute with the given name. But you cannot use the syntax object.”attribute” because the dot notation only allows for name-access like this: object.attribute. How do you resolve this problem? … Read more

Python String Formatting: How to Become a String Wizard with the Format Specification Mini-Language

Python provides fantastic string formatting options, but what if you need greater control over how values are presented? That’s where format specifiers come in.  This article starts with a brief overview of the different string formatting approaches. We’ll then dive straight into some examples to whet your appetite for using Python’s Format Specification Mini-Language in … Read more

How to Print Without Newline in Python—A Simple Illustrated Guide

Summary: To print without the newline character in Python 3, set the end argument in the print() function to the empty string or the single whitespace character. This ensures that there won’t be a newline in the standard output after each execution of print(). Alternatively, unpack the iterable into the print() function to avoid the … Read more

What is the Asterisk / Star Operator (*) in Python?

Asterisk Operator

Many Python coders—even at intermediate skill levels—are often puzzled when it comes to the asterisk character in Python. What does it mean? How does it work? What’s it purpose? This article answers all of those questions and more. After studying this article, you will have a solid understanding of the asterisk operator * in Python—and … Read more