Previous Page Next Page Python is available on a wide variety of platforms including Linux and Mac OS X. Lets understand how to set up our Python environment. Local Environment Setup Open a terminal window and type python to find out if it is already installed and which version is ins
Previous Page Next Page Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than othe
In case you missed it: Python 2 is officially not supported as of January 1, 2020. If you’re still on Python 2.7, upgrade now. If you’re not sure what version you’re runing, check your Python version. Many package maintainers have migrated to Python 3. Some still
You can check for the Python version in your code, to make sure your users are not running your script with an incompatible version. Use this simple check: = (3, 5): # Kindly tell your user (s)he needs to upgrade # because youre using 3.5 features
IPython is an enhanced Python REPL, and it’s actually the core for Jupyter notebook. In short, Jupyter is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. If you use the interactive shell a lot
With sys.getsizeof() you can check the memory usage of an object: import sys mylist = range(0, 10000) print(sys.getsizeof(mylist)) # 48 Woah… wait… why is this huge list only 48 bytes? It’s because the range function returns an iterable object that only behaves like a list of numbers, but inter
With Python, we can return multiple values at once. Obviously, most functions in Python return a single value, usually the result of the work done by that function. In this article, you’ll learn that you can return multiple values in Python too, and you don’t need a dictionary, list,
A Python data class is a regular Python class that has the @dataclass decorator. It is specifically created to hold data. Since Python version 3.7, Python offers data classes through a built-in module called dataclass. There are several advantages over regular Python classes which we’ll ex
With this neat little trick, you can swap two Python variables without using a third variable: a = 1 b = 2 a, b = b, a print (a) # 2 print (b) # 1 It’s just one line of code! As you can see in line 3, no temporary variable is needed to swap variables in Python.
With this trick, you can quickly convert a Python string to title case. To quote from the Wikipedia article: Title case is often used, both in offline and online printing. This site itself uses title case for all its articles. If you look closely, you’ll notice most websites, newspapers,
There’s a package for pretty much everything you can think of in the Python ecosystem, all installable with a simple pip command. So it shouldn’t surprise anyone that there’s a package to work with emoji in Python, too. You can install the emoji package with: $ pip3 install emo
The Pillow Python Imaging Library is ideal for image processing. Typically, it’s used for archival and batch processing applications. Of course, you’re free to use it for anything else you can think of. You can use the library to: Create thumbnailsConvert between file formats,Print i
One of the earliest Python pep’s is PEP-20. It’s a list of 19 theses relating to Python programming called ‘The Zen of Python.’ These rules date back to 2004 and are in turn based on PEP-8. A little Easter egg that has been present in Python for a long time lists these 19
You can obtain the result of the last expression in a Python REPL with the underscore operator, e.g. in the Python REPL this looks like: _ + 3 12 This works in the IPython shell too. In addition, the IPython shell allows you to use Out[n] to get the value of the expression I
The package Python Attrs allows you to create advanced data classes using simple annotations. Of course, python has its own native data class module as well, but the Python attrs package offers a couple of extra features you might like! Table of contents Install attrsAttrs vs data classesA ba
Python class slots are a feature that not many programmers know of. In a slotted class we explicitly define the fields that our class is allowed to have using the magic field name __slots__. This has some advantages: Objects created from the class will take up slightly less memoryIt’s faster to
I see lots of people handling exceptions the wrong way. Perhaps this applies to you too. Does the following situation sound familiar? You’re writing some code, but you know that the library you’re using might raise an exception. You don’t remember which one, exactly. At this po
Debugging Python code, for many of us, comes down to adding print statements and trying to reason what’s going on based on the output. It’s not ideal, but for some reason, people just don’t want to touch the Python debugger. Table of contents Using print to debug codeSetting a Python debugger
What are Python Modules? A module is a single Python file that can contain variables, functions, and classes. When you name the file guru99.py, the module is accessed as guru99. Modules let you split a large program into logical pieces, keeping your code organized and reusable. Why Import Modules?
Python offers both multiprocessing and multithreading to accelerate workloads. This guide walks you through creating robust, thread‑based applications, the nuances of the Global Interpreter Lock (GIL), and how to avoid common pitfalls like deadlocks and race conditions. What Is a Thread? A thread is
Python
US Army Explores Smart City Technologies to Boost Battlefield Effectiveness
Mats vs. Insoles: A Professional Guide to Choosing the Right Support for Your Workplace
Service Mesh Explained: How Open‑Source Meshes Simplify Microservice Communication
Understanding the Formation of Au-Catalyzed InGaAs Nanowires via Solid-Source Two-Step CVD