Let me show you how to join the latest Disney Pixar AI dog trend in 5 minutes. This is super easy with today’s AI-powered tools. How Does It Work? These days, you don’t need to be a designer or photographer to create astounding images. Instead, you can let the AI take care of all of […]
Are you looking for a career as a data scientist? In this article, you find a list of useful, practical, and comprehensive data science courses taught entirely in Python. Before jumping into the courses, I’d like to offer you a quick primer on what is data science and how is Python used in data science.
To check if an object has an attribute in Python, you can use the hasattr() function. This function takes two arguments: the object that you want to check, and the name of the attribute that you are looking for. For example: In this example, hasattr(obj, ‘attr’) will return True, because obj has the attribute attr.
To remove a non-empty folder in Python, you can use the shutil module, which provides functions for copying and removing files and directories. ATTENTION! This guide shows you how to permanently delete the files and directories. Make sure you’ve crafted the file paths so that you’re 100% sure to delete the directories you want to
In Python, there’s no tuple comprehension. However, you can mimic the tuple comprehensions by running a generator expression inside tuple() function call. For example: This guide teaches you how to mimic the behavior of tuple comprehensions by using generator expressions inside the tuple() function. You will learn what is a generator expression and how the
To split a list into N chunks in Python, you can use iterators: Notice that it isn’t always possible to produce a list where the chunks are equal in length. This is because the list elements might not be evenly divisible to the N chunks. This is a comprehensive guide to splitting a list into
To check the size of a file in Python, use the os.path.getsize() method. This method takes the path of the file as an argument and returns the size of the file in bytes. The os module is part of the standard library. Thus, you do not need to install it. It is available out of
Python does not have traditional increment and decrement operators, like ++ or –. Instead, Python uses augmented assignment operators, which combine the assignment operator (=) with a mathematical operation, such as addition (+=) or subtraction (-=). For example, to increment a variable x by 1, you can use the augmented assignment operator x += 1
In Python, the dir() function returns a list of the attributes and methods that belong to an object. This can be useful for exploring and discovering the capabilities of an object, as well as for debugging and testing. For example, let’s list the attributes associated with a Python string: Output: The result is a complete
To get the size of a Python object, you can use the getsizeof() function from the sys module. This function returns the size of an object in bytes. For example, let’s print the size of a list and the size of an integer: Output: ⚠️ Keep in mind that sys.getsizeof() function only returns the size