Python tutorials

Interacting With Python

There are multiple ways of interacting with Python, and each can be useful for different scenarios. You can quickly explore functionality in Python’s interactive mode using the built-in Read-Eval-Print Loop (REPL), or you can write larger applications to a script file using an editor or Integrated Development Environment (IDE). In this tutorial, you’ll learn how to: Use Python interactively by typing code directly into the interpreter Execute code contained in a script file from the command line Work within a […]

Read more

Using the Python zip() Function for Parallel Iteration

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Parallel Iteration With Python’s zip() Function Python’s zip() function combines elements from multiple iterables. Calling zip() generates an iterator that yields tuples, each containing elements from the input iterables. This function is essential for tasks like parallel iteration and dictionary creation, offering an efficient way to handle multiple sequences in Python programming. By the […]

Read more

Quiz: Namespaces and Scope in Python

Interactive Quiz ⋅ 11 QuestionsBy Martin Breuss Share In this quiz, you’ll test your understanding of Python Namespaces and Scope. You’ll revisit how Python organizes symbolic names and objects in namespaces, when Python creates a new namespace, how namespaces are implemented, and how variable scope determines symbolic name visibility. The quiz contains 11 questions and there is no time limit. You’ll get 1 point for each correct answer. At the end of the quiz, you’ll receive a total score. The […]

Read more

Quiz: Basic Input and Output in Python

Interactive Quiz ⋅ 5 QuestionsBy Martin Breuss Share In this quiz, you’ll test your understanding of how to use Python’s built-in functions input() and print() for basic input and output operations. You’ll also revisit how to use readline to improve the user experience when collecting input, and how to format output using the sep and end keyword arguments of print(). The quiz contains 5 questions and there is no time limit. You’ll get 1 point for each correct answer. At […]

Read more

Using portable SIMD in stable Rust

In a previous post we saw that you can speed up code significantly on a single core using SIMD: Single Instruction Multiple Data. These specialized CPU instructions allow you to, for example, add 4 values at once with a single instruction, instead of the usual one value at a time. The performance improvement you get compounds with multi-core parallelism: you can benefit from both SIMD and threading at the same time. Unfortunately, SIMD instructions are specific both to CPU architecture […]

Read more

Python Dictionary Comprehensions: How and When to Use Them

Dictionary comprehensions are a concise and quick way to create, transform, and filter dictionaries in Python. They can significantly enhance your code’s conciseness and readability compared to using regular for loops to process your dictionaries. Understanding dictionary comprehensions is crucial for you as a Python developer because they’re a Pythonic tool for dictionary manipulation and can be a valuable addition to your programming toolkit. In this tutorial, you’ll learn how to: Create dictionaries using dictionary comprehensions Transform existing dictionaries with […]

Read more

Formatting Floats Inside Python F-Strings

You’ll often need to format and round a Python float to display the results of your calculations neatly within strings. In earlier versions of Python, this was a messy thing to do because you needed to round your numbers first and then use either string concatenation or the old string formatting technique to do this for you. Since Python 3.6, the literal string interpolation, more commonly known as a formatted string literal or f-string, allows you to customize the content […]

Read more

Python News Roundup: November 2024

The latest Python developments all point to the same thing—Python is currently thriving. The recent GitHub Octoverse 2024 report has revealed that Python is now the most used language on GitHub. Also, last month saw the release of Python 3.13, which is already laying the groundwork for some exciting future improvements. While Python core developers have been busy exploring the language’s features as they tinker with upcoming enhancements, it’s good to know that working on Python’s source code isn’t the […]

Read more

How to Reset a pandas DataFrame Index

In this tutorial, you’ll learn how to reset a pandas DataFrame index, the reasons why you might want to do this, and the problems that could occur if you don’t. Before you start your learning journey, you should familiarize yourself with how to create a pandas DataFrame. Knowing the difference between a DataFrame and a pandas Series will also prove useful to you. In addition, you may want to use the data analysis tool Jupyter Notebook as you work through […]

Read more

Quiz: Variables in Python: Usage and Best Practices

Interactive Quiz ⋅ 16 QuestionsBy Leodanis Pozo Ramos Share In this quiz, you’ll test your understanding of Variables in Python: Usage and Best Practices. By working through this quiz, you’ll revisit how to create and assign values to variables, change a variable’s data type dynamically, use variables to create expressions, counters, accumulators, and Boolean flags, follow best practices for naming variables, and create, access, and use variables in their scopes. The quiz contains 16 questions and there is no time […]

Read more
1 2 3 4 5 182