Python 3.12 Preview: Static Typing Improvements

Python’s support for static typing gradually improves with each new release of Python. The core features were in place in Python 3.5. Since then, there’ve been many tweaks and improvements to the type hinting system. This evolution continues in Python 3.12, which, in particular, simplifies the typing of generics. In this tutorial, you’ll: Use type variables in Python to annotate generic classes and functions Explore the new syntax for type hinting type variables Model inheritance with the new @override decorator […]

Read more

Python Basics Exercises: Conditional Logic and Control Flow

In Python Basics: Conditional Logic and Control Flow, you learned that much of the Python code you’ll write is unconditional. That is, the code doesn’t make any choices. Every line of code is executed in the order that it’s written or in the order that functions are called, with possible repetitions inside loops. In this course, you’ll revisit how to use conditional logic to write programs that perform different actions based on different conditions. Paired with functions and loops, conditional […]

Read more

Python 3.12 Preview: Subinterpreters

Now that you know what a Python subinterpreter is, you’ll take a look at what’s changing in the upcoming releases of CPython. Most of the subinterpreter changes are described in two proposals, PEP 684 and PEP 554. Only PEP 684 will make it into the 3.12 release. PEP 554 is scheduled for the 3.13 release but hasn’t been officially approved yet. Changes to the Global State and the GIL The main focus of PEP 684 is refactoring the internals of […]

Read more

Speeding up your code when multiple cores aren’t an option

The common advice when Python is too slow is to switch to a low-level compiled language like Cython or Rust. But what do you do if that code is too slow? At that point you might start thinking about parallelism: using multi-threading or multi-processing so you can take advantage of multiple CPU cores. But parallelism comes with its own set of complexities; at the very least, some algorithms can only really work in a single-threaded way. So what can you […]

Read more

How to Catch Multiple Exceptions in Python

In this tutorial, you’ll learn various techniques to catch multiple exceptions with Python. To begin with, you’ll review Python’s exception handling mechanism before diving deeper and learning how to identify what you’ve caught, sometimes ignore what you’ve caught, and even catch lots of exceptions. Python raises an exception when your code encounters an occasional but not unexpected error. For example, this will occur if you try to read a missing file. Because you’re aware that such exceptions may occur, you […]

Read more

Design and Guidance: Object-Oriented Programming in Python

Writing good object-oriented code is about more than just how to write the syntax. Knowing when and when not to use it, as well as guiding principles behind object-oriented design will help you write better code. In this course, you’ll learn about: The objected-oriented approach in Python vs other languages Cases in which you shouldn’t use classes in Python Alternatives to inheritance in structuring your code The SOLID principles for improving your code SOLID is an acronym for five principles […]

Read more

Operators and Expressions in Python

In Python, operators are special symbols, combinations of symbols, or keywords that designate some type of computation. You can combine objects and operators to build expressions that perform the actual computation. So, operators are the building blocks of expressions, which you can use to manipulate your data. Therefore, understanding how operators work in Python is essential for you as a programmer. In this tutorial, you’ll learn about the operators that Python currently supports. You’ll also learn the basics of how […]

Read more

Bypassing the GIL for Parallel Processing in Python

Unlocking Python’s true potential in terms of speed through shared-memory parallelism has traditionally been limited and challenging to achieve. That’s because the global interpreter lock (GIL) doesn’t allow for thread-based parallel processing in Python. Fortunately, there are several work-arounds for this notorious limitation, which you’re about to explore now! To get the most out of this advanced tutorial, you should understand the difference between concurrency and parallelism. You’ll benefit from having previous experience with multithreading in programming languages other than […]

Read more

Inheritance and Internals: Object-Oriented Programming in Python

Python includes mechanisms for writing object-oriented code where the data and operations on that data are structured together. The class keyword is how you create these structures in Python. The definition of a class can be based on other classes, allowing the creation of hierarchical structures and promoting code reuse. This mechanism is known as inheritance. In this course, you’ll learn about: Basic class inheritance Multi-level inheritance, or classes that inherit from classes Classes that inherit directly from more than […]

Read more

Object-Oriented Programming (OOP) in Python 3

Object-oriented programming (OOP) is a method of structuring a program by bundling related properties and behaviors into individual objects. In this tutorial, you’ll learn the basics of object-oriented programming in Python. Conceptually, objects are like the components of a system. Think of a program as a factory assembly line of sorts. At each step of the assembly line, a system component processes some material, ultimately transforming raw material into a finished product. An object contains data, like the raw or […]

Read more
1 82 83 84 85 86 908