Movatterモバイル変換


[0]ホーム

URL:


— FREE Email Series —

🐍 Python Tricks 💌

Python Tricks Dictionary Merge

🔒 No spam. Unsubscribe any time.

Browse TopicsGuided Learning Paths
Basics Intermediate Advanced
aialgorithmsapibest-practicescareercommunitydatabasesdata-sciencedata-structuresdata-vizdevopsdjangodockereditorsflaskfront-endgamedevguimachine-learningnewsnumpyprojectspythonstdlibtestingtoolsweb-devweb-scraping

Table of Contents

Recommended Course

Python's filter(): Extract Values From Iterables

Filtering Iterables With Python

54m · 13 lessons

Python's filter(): Extract Values From Iterables

Python's filter(): Extract Values From Iterables

byLeodanis Pozo RamosReading time estimate 25mintermediatebest-practicespython

Table of Contents

Remove ads

Recommended Course

Filtering Iterables With Python(54m)

Python’sfilter() is a built-in function that allows you to process an iterable and extract those items that satisfy a given condition. This process is commonly known as afiltering operation. Withfilter(), you can apply afiltering function to an iterable and produce a new iterable with the items that satisfy the condition at hand. In Python,filter() is one of the tools you can use forfunctional programming.

In this tutorial, you’ll learn how to:

  • Use Python’sfilter() in your code
  • Extractneeded values from your iterables
  • Combinefilter() with otherfunctional tools
  • Replacefilter() with morePythonic tools

With this knowledge, you’ll be able to usefilter() effectively in your code. Alternatively, you have the choice of usinglist comprehensions orgenerator expressions to write morePythonic and readable code.

To better understandfilter(), it would be helpful for you to have some previous knowledge oniterables,for loops,functions, andlambda functions.

Free Bonus:5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you’ll need to take your Python skills to the next level.

Coding With Functional Style in Python

Functional programming is a paradigm that promotes using functions to perform almost every task in a program. A pure functional style relies on functions that don’t modify their input arguments and don’t change the program’s state. They just take a specific set of arguments andreturn the same result every time. These kinds of functions are known aspure functions.

In functional programming, functions often operate on arrays of data, transform them, and produce new arrays with added features. There are three fundamental operations in functional programming:

  1. Mapping applies a transformation function to an iterable and produces a new iterable of transformed items.
  2. Filtering applies apredicate, or Boolean-valued, function to an iterable and generates a new iterable containing the items that satisfy theBoolean condition.
  3. Reducing applies a reduction function to an iterable and returns a single cumulative value.

Pythonisn’t heavily influenced by functional languages but byimperative ones. However, it provides several features that allow you to use a functional style:

Functions in Python arefirst-class objects, which means that you can pass them around as you’d do with any other object. You can also use them as arguments and return values of other functions. Functions that accept other functions as arguments or that return functions (or both) are known ashigher-order functions, which are also a desirable feature in functional programming.

In this tutorial, you’ll learn aboutfilter(). This built-in function is one of the more popular functional tools of Python.

Understanding the Filtering Problem

Say you need to process alist ofnumbers and return a new list containing only those numbers greater than0. A quick way to approach this problem is to use afor loop like this:

Python
>>>numbers=[-2,-1,0,1,2]>>>defextract_positive(numbers):...positive_numbers=[]...fornumberinnumbers:...ifnumber>0:# Filtering condition...positive_numbers.append(number)...returnpositive_numbers...>>>extract_positive(numbers)[1, 2]

The loop inextract_positive() iterates throughnumbers and stores every number greater than0 inpositive_numbers. Theconditional statementfilters out the negative numbers and0. This kind of functionality is known as afiltering.

Filtering operations consist of testing each value in an iterable with apredicate function and retaining only those values for which the function produces a true result. Filtering operations are fairly common in programming, so most programming languages provide tools to approach them. In the next section, you’ll learn about Python’s way to filter iterables.

Getting Started With Python’sfilter()

Python provides a convenient built-in function,filter(), that abstracts out the logic behind filtering operations. Here’s its signature:

Python
filter(function,iterable)

The first argument,function, must be a single-argument function. Typically, you provide a predicate (Boolean-valued) function to this argument. In other words, you provide a function that returns eitherTrue orFalse according to a specific condition.

Thisfunction plays the role of adecision function, also known as afiltering function, because it provides the criteria to filter out unwanted values from the input iterable and to keep those values that you want in the resulting iterable. Note that the termunwanted values refers to those values that evaluate to false whenfilter() processes them usingfunction.

Note: The first argument tofilter() is afunction object, which means that you need to pass a function without calling it with a pair of parentheses.

The second argument,iterable, can hold any Python iterable, such as alist, tuple, orset. It can also hold generator and iterator objects. An important point regardingfilter() is that it accepts only oneiterable.

To perform the filtering process,filter() appliesfunction to every item ofiterable in a loop. The result is an iterator that yields the values ofiterable for whichfunction returns a true value. The process doesn’t modify the original input iterable.

Sincefilter() is written inC and is highly optimized, its internal implicit loop can be more efficient than a regularfor loop regarding execution time. This efficiency is arguably the most important advantage of using the function in Python.

A second advantage of usingfilter() over a loop is that it returns afilter object, which is an iterator that yields values on demand, promoting alazy evaluation strategy. Returning an iterator makesfilter() more memory efficient than an equivalentfor loop.

Note: In Python 2.x,filter() returnslist objects. This behavior changed inPython 3.x. Now the function returns afilter object, which is an iterator that yields items on demand. Python iterators are well known to be memory efficient.

In your example about positive numbers, you can usefilter() along with a convenient predicate function to extract the desired numbers. To code the predicate, you can use either alambda or a user-defined function:

Python
>>>numbers=[-2,-1,0,1,2]>>># Using a lambda function>>>positive_numbers=filter(lambdan:n>0,numbers)>>>positive_numbers<filter object at 0x7f3632683610>>>>list(positive_numbers)[1, 2]>>># Using a user-defined function>>>defis_positive(n):...returnn>0...>>>list(filter(is_positive,numbers))[1, 2]

In the first example, you use alambda function that provides the filtering functionality. The call tofilter() applies thatlambda function to every value innumbers and filters out the negative numbers and0. Sincefilter() returns an iterator, you need to calllist() to consume the iterator and create the final list.

Note: Sincefilter() is a built-in function, you don’t have toimport anything to be able to use it in your code.

In the second example, you writeis_positive() to take a number as an argument and returnTrue if the number is greater than0. Otherwise, it returnsFalse. The call tofilter() appliesis_positive() to every value innumbers, filtering out the negative numbers. This solution is way more readable than itslambda equivalent.

In practice,filter() isn’t limited to Boolean functions such as those in the examples above. You can use other types of functions, andfilter() will evaluate their return value for truthiness:

Python
>>>defidentity(x):...returnx...>>>identity(42)42>>>objects=[0,1,[],4,5,"",None,8]>>>list(filter(identity,objects))[1, 4, 5, 8]

In this example, the filtering function,identity(), doesn’t returnTrue orFalse explicitly but the same argument it takes. Since0,[],"", andNone are falsy,filter() uses theirtruth value to filter them out. The final list contains only those values that are truthy in Python.

Note: Python follows a set of rules to determine an object’s truth value.

For example, the followingobjects are falsy:

  • Constants likeNone andFalse
  • Numeric types with a zero value, like0,0.0,0j,Decimal(0), andFraction(0, 1)
  • Empty sequences and collections, like"",(),[],{},set(), andrange(0)
  • Objects that implement__bool__() with a return value ofFalse or__len__() with a return value of0

Any other object will be considered truthy.

Finally, if you passNone tofunction, thenfilter() uses theidentity function and yields all the elements ofiterable that evaluate toTrue:

Python
>>>objects=[0,1,[],4,5,"",None,8]>>>list(filter(None,objects))[1, 4, 5, 8]

In this case,filter() tests every item in the input iterable using the Python rules you saw before. Then it yields those items that evaluate toTrue.

So far, you’ve learned the basics offilter() and how it works. In the following sections, you’ll learn how to usefilter() to process iterables and throw away unwanted values without a loop.

Filtering Iterables Withfilter()

The job offilter() is to apply a decision function to each value in an input iterable and return a new iterable with those items that pass the test. The following sections provide some practical examples so you can get up and running withfilter().

Extracting Even Numbers

As a first example, say you need to process a list of integer numbers and build a new list containing the even numbers. Your first approach to this problem might be to use afor loop like this:

Python
>>>numbers=[1,3,10,45,6,50]>>>defextract_even(numbers):...even_numbers=[]...fornumberinnumbers:...ifnumber%2==0:# Filtering condition...even_numbers.append(number)...returneven_numbers...>>>extract_even(numbers)[10, 6, 50]

Here,extract_even() takes an iterable of integer numbers and returns a list containing only those that are even. The conditional statement plays the role of a filter that tests every number to find out if it’s even or not.

When you run into code like this, you can extract the filtering logic into a small predicate function and use it withfilter(). This way, you can perform the same computation without using an explicit loop:

Python
>>>numbers=[1,3,10,45,6,50]>>>defis_even(number):...returnnumber%2==0# Filtering condition...>>>list(filter(is_even,numbers))[10, 6, 50]

Here,is_even() takes an integer and returnsTrue if it’s even andFalse otherwise. The call tofilter() does the hard work and filters out the odd numbers. As a result, you get a list of the even numbers. This code is shorter and more efficient than its equivalentfor loop.

Finding Prime Numbers

Another interesting example might be to extract all theprime numbers in a given interval. To do that, you can start by coding a predicate function that takes an integer as an argument and returnsTrue if the number is prime andFalse otherwise. Here’s how you can do that:

Python
>>>importmath>>>defis_prime(n):...ifn<=1:...returnFalse...foriinrange(2,int(math.sqrt(n))+1):...ifn%i==0:...returnFalse...returnTrue...>>>is_prime(5)True>>>is_prime(12)False

The filtering logic is now inis_prime(). The function iterates through the integers between2 and thesquare root ofn. Inside the loop, theconditional statement checks if the current number is divisible by any other in the interval. If so, then the function returnsFalse because the number isn’t prime. Otherwise, it returnsTrue to signal that the input number is prime.

Withis_prime() in place and tested, you can usefilter() to extract prime numbers from an interval like this:

Python
>>>list(filter(is_prime,range(1,51)))[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

This call tofilter() extracts all the prime numbers in the range between1 and50. The algorithm used inis_prime() comes from Wikipedia’s article aboutprimality tests. You can check out that article if you need more efficient approaches.

Removing Outliers in a Sample

When you’re trying todescribe and summarize a sample of data, you probably start by finding its mean, or average. The mean is a quite popularcentral tendency measurement and is often the first approach to analyzing a dataset. It gives you a quick idea of the center, orlocation, of the data.

In some cases, the mean isn’t a good enough central tendency measure for a given sample.Outliers are one of the elements that affect how accurate the mean is. Outliers aredata points that differ significantly from other observations in a sample or population. Other than that, there is no unique mathematical definition for them in statistics.

However, innormally distributed samples, outliers are often defined as data points that lie more than twostandard deviations from the sample mean.

Now suppose you have a normally distributed sample with some outliers that are affecting the mean accuracy. You’ve studied the outliers, and you know they’re incorrect data points. Here’s how you can use a couple of functions from thestatistics module along withfilter() to clean up your data:

Python
>>>importstatisticsasst>>>sample=[10,8,10,8,2,7,9,3,34,9,5,9,25]>>># The mean before removing outliers>>>mean=st.mean(sample)>>>mean10.692307692307692>>>stdev=st.stdev(sample)>>>low=mean-2*stdev>>>high=mean+2*stdev>>>clean_sample=list(filter(lambdax:low<=x<=high,sample))>>>clean_sample[10, 8, 10, 8, 2, 7, 9, 3, 9, 5, 9, 25]>>># The mean after removing outliers>>>st.mean(clean_sample)8.75

In the highlighted line, thelambda function returnsTrue if a given data point lies between the mean and two standard deviations. Otherwise, it returnsFalse. When you filter thesample with this function,34 is excluded. After this cleanup, the mean of the sample has a significantly different value.

Validating Python Identifiers

You can also usefilter() with iterables containing nonnumeric data. For example, say you need to process a list ofstrings and extract those that are valid Pythonidentifiers. After doing some research, you find out that Python’sstr provides a method called.isidentifier() that can help you out with that validation.

Here’s how you can usefilter() along withstr.isidentifier() to quickly validate identifiers:

Python
>>>words=["variable","file#","header","_non_public","123Class"]>>>list(filter(str.isidentifier,words))['variable', 'header', '_non_public']

In this case,filter() runs.isidentifier() on every string inwords. If the string is a valid Python identifier, then it’s included in the final result. Otherwise, the word is filtered out. Note that you need to usestr to access.isidentifier() in the call tofilter().

Note: Besides.isidentifier(),str provides a rich set of.is*()methods that can be useful for filtering iterables of strings.

Finally, an interesting exercise might be to take the example further and check if the identifier is also akeyword. Go ahead and give it a try! Hint: you can use.kwlist from thekeyword module.

Finding Palindrome Words

An exercise that often arises when you’re getting familiar with Python strings is to findpalindrome words in a list of strings. A palindrome word reads the same backward as forward. Typical examples are “madam” and “racecar.”

To solve this problem, you’ll start by coding a predicate function that takes a string and checks if it reads the same in both directions, backward and forward. Here’s a possible implementation:

Python
>>>defis_palindrome(word):...reversed_word="".join(reversed(word))...returnword.lower()==reversed_word.lower()...>>>is_palindrome("Racecar")True>>>is_palindrome("Python")False

Inis_palindrome(), you first reverse the originalword and store it inreversed_word. Then you return the result of comparing both words for equality. In this case, you use.lower() to prevent case-related differences. If you call the function with a palindrome word, then you getTrue. Otherwise, you getFalse.

You already have a working predicate function to identify palindrome words. Here’s how you can usefilter() to do the hard work:

Python
>>>words=("filter","Ana","hello","world","madam","racecar")>>>list(filter(is_palindrome,words))['Ana', 'madam', 'racecar']

Cool! Your combination offilter() andis_palindrome() works properly. It’s also concise, readable, and efficient. Good job!

Combiningfilter() With Other Functional Tools

So far, you’ve learned how to usefilter() to run different filtering operations on iterables. In practice, you can combinefilter() with other functional tools to perform many different tasks on iterables without using explicit loops. In the next two sections, you’ll learn the basics of usingfilter() along withmap() andreduce().

The Square of Even Numbers:filter() andmap()

Sometimes you need to take an iterable, process each of its items with atransformation function, and produce a new iterable with the resulting items. In that case, you can usemap(). The function has the following signature:

Python
map(function,iterable[,iterable1,...,iterableN])

The arguments work like this:

  1. function holds the transformation function. This function should take as many arguments as iterables you pass intomap().
  2. iterable holds a Python iterable. Note that you can provide several iterables tomap(), but that’s optional.

map() appliesfunction to each item initerable to transform it into a different value with additional features. Thenmap() yields each transformed item on demand.

To illustrate how you can usefilter() along withmap(), say you need to compute the square value of all the even numbers in a given list. In that case, you can usefilter() to extract the even numbers and thenmap() to calculate the square values:

Python
>>>numbers=[1,3,10,45,6,50]>>>defis_even(number):...returnnumber%2==0...>>>even_numbers=list(filter(is_even,numbers))>>>even_numbers[10, 6, 50]>>>list(map(lambdan:n**2,even_numbers))[100, 36, 2500]>>>list(map(lambdan:n**2,filter(is_even,numbers)))[100, 36, 2500]

First, you get the even numbers usingfilter() andis_even() just like you’ve done so far. Then you callmap() with alambda function that takes a number and returns its square value. The call tomap() applies thelambda function to each number ineven_numbers, so you get a list of square even numbers. The final example shows how to combinefilter() andmap() in a single expression.

The Sum of Even Numbers:filter() andreduce()

Another functional programming tool in Python isreduce(). Unlikefilter() andmap(), which are still built-in functions,reduce() was moved to thefunctools module. This function is useful when you need to apply a function to an iterable and reduce it to a single cumulative value. This kind of operation is commonly known as areduction or folding.

The signature ofreduce() is like this:

Python
reduce(function,iterable,initial)

Here’s what the arguments mean:

  1. function holds any Python callable that accepts two arguments and returns a single value.
  2. iterable holds any Python iterable.
  3. initial holds a value that serves as a starting point for the first partial computation or reduction. It’s an optional argument.

A call toreduce() starts by applyingfunction to the first two items initerable. This way, it computes the first cumulative result, called anaccumulator. Thenreduce() uses the accumulator and the third item initerable to compute the next cumulative result. The process continues until the function returns with a single value.

If you supply a value toinitial, thenreduce() runs the first partial computation usinginitial and the first item ofiterable.

Here’s an example that combinesfilter() andreduce() to cumulatively calculate the total sum of all the even numbers in a list:

Python
>>>fromfunctoolsimportreduce>>>numbers=[1,3,10,45,6,50]>>>defis_even(number):...returnnumber%2==0...>>>even_numbers=list(filter(is_even,numbers))>>>reduce(lambdaa,b:a+b,even_numbers)66>>>reduce(lambdaa,b:a+b,filter(is_even,numbers))66

Here, the first call toreduce() computes the sum of all the even numbers thatfilter() provides. To do that,reduce() uses alambda function that adds two numbers at a time.

The final example shows how to chainfilter() andreduce() to produce the same result you got before.

Filtering Iterables Withfilterfalse()

Initertools, you’ll find a function calledfilterfalse() that does the inverse offilter(). It takes an iterable as argument and returns a new iterator that yields the items for which the decision function returns a false result. If you useNone as the first argument tofilterfalse(), then you get the items that are falsy.

The point of having thefilterfalse() function is to promotecode reuse. If you already have a decision function in place, then you can use it withfilterfalse() to get the rejected items. This saves you from coding an inverse decision function.

In the following sections, you’ll code some examples that show how you can take advantage offilterfalse() to reuse existing decision functions and continue doing some filtering.

Extracting Odd Numbers

You already coded a predicate function calledis_even() to check if a number is even or not. With that function and the help offilterfalse(), you can build an iterator that yields odd numbers without having to code anis_odd() function:

Python
>>>fromitertoolsimportfilterfalse>>>numbers=[1,3,10,45,6,50]>>>defis_even(number):...returnnumber%2==0...>>>list(filterfalse(is_even,numbers))[1, 3, 45]

In this example,filterfalse() returns an iterator that yields the odd numbers from the input iterator. Note that the call tofilterfalse() is straightforward and readable.

Filtering Out NaN Values

Sometimes when you’re working withfloating-point arithmetic, you can face the issue of havingNaN (not a number) values. For example, say you’re calculating the mean of a sample of data that contains NaN values. If you use Python’sstatistics module for this computation, then you get the following result:

Python
>>>importstatisticsasst>>>sample=[10.1,8.3,10.4,8.8,float("nan"),7.2,float("nan")]>>>st.mean(sample)nan

In this example, the call tomean() returnsnan, which isn’t the most informative value you can get. NaN values can have different origins. They can be due to invalid inputs, corrupted data, and so on. You should find the right strategy to deal with them in your applications. One alternative might be to remove them from your data.

Themath module provides a convenient function calledisnan() that can help you out with this problem. The function takes a numberx as an argument and returnsTrue ifx is a NaN andFalse otherwise. You can use this function to provide the filtering criteria in afilterfalse() call:

Python
>>>importmath>>>importstatisticsasst>>>fromitertoolsimportfilterfalse>>>sample=[10.1,8.3,10.4,8.8,float("nan"),7.2,float("nan")]>>>st.mean(filterfalse(math.isnan,sample))8.96

Usingmath.isnan() along withfilterfalse() allows you to exclude all the NaN values from the mean computation. Note that after the filtering, the call tomean() returns a value that provides a better description of your sample data.

Coding With Pythonic Style

Even thoughmap(),filter(), andreduce() have been around for a long time in the Python ecosystem,list comprehensions andgenerator expressions have become strong and Pythonic competitors in almost every use case.

The functionality these functions provide is almost always more explicitly expressed using a generator expression or a list comprehension. In the following two sections, you’ll learn how to replace a call tofilter() with a list comprehension or a generator expression. This replacement will make your code more Pythonic.

Replacingfilter() With a List Comprehension

You can use the following pattern to quickly replace a call tofilter() with an equivalent list comprehension:

Python
# Generating a list with filter()list(filter(function,iterable))# Generating a list with a list comprehension[itemforiteminiterableiffunction(item)]

In both cases, the final purpose is to create a list object. The list comprehension approach is more explicit than its equivalentfilter() construct. A quick read through the comprehension reveals the iteration and also the filtering functionality in theif clause.

Using list comprehensions instead offilter() is probably the path most Python developers take nowadays. However, list comprehensions have some drawbacks compared tofilter(). The most notable one is the lack of lazy evaluation. Also, when developers start reading code that usesfilter(), they immediately know that the code is performing filtering operations. However, that’s not so evident in code that uses list comprehensions with the same goal.

A detail to notice when turning afilter() construct into a list comprehension is that if you passNone to the first argument offilter(), then the equivalent list comprehension looks like this:

Python
# Generating a list with filter() and Nonelist(filter(None,iterable))# Equivalent list comprehension[itemforiteminiterableifitem]

In this case, theif clause in the list comprehension testsitem for its truth value. This test follows the standard Python rules about truth values you already saw.

Here’s an example of replacingfilter() with a list comprehension to build a list of even numbers:

Python
>>>numbers=[1,3,10,45,6,50]>>># Filtering function>>>defis_even(x):...returnx%2==0...>>># Use filter()>>>list(filter(is_even,numbers))[10, 6, 50]>>># Use a list comprehension>>>[numberfornumberinnumbersifis_even(number)][10, 6, 50]

In this example, you can see that the list comprehension variant is more explicit. It reads almost like plain English. The list comprehension solution also avoids having to calllist() to build the final list.

Replacingfilter() With a Generator Expression

The natural replacement forfilter() is agenerator expression. That’s becausefilter() returns an iterator that yields items on demand just like a generator expression does. Python iterators are known to be memory efficient. That’s whyfilter() now returns an iterator instead of a list.

Here’s how you can use generator expressions to write the example in the above section:

Python
>>>numbers=[1,3,10,45,6,50]>>># Filtering function>>>defis_even(x):...returnx%2==0...>>># Use filter()>>>even_numbers=filter(is_even,numbers)>>>even_numbers<filter object at 0x7f58691de4c0>>>>list(even_numbers)[10, 6, 50]>>># Use a generator expression>>>even_numbers=(numberfornumberinnumbersifis_even(number))>>>even_numbers<generator object <genexpr> at 0x7f586ade04a0>>>>list(even_numbers)[10, 6, 50]

A generator expression is as efficient as a call tofilter() in terms of memory consumption. Both tools return iterators that yield items on demand. Using either one might be a question of taste, convenience, or style. So, you’re in charge!

Conclusion

Python’sfilter() allows you to performfiltering operations on iterables. This kind of operation consists of applying aBoolean function to the items in an iterable and keeping only those values for which the function returns a true result. In general, you can usefilter() to process existing iterables and produce new iterables containing the values that you currently need.

In this tutorial, you learned how to:

  • Work with Python’sfilter()
  • Usefilter() toprocess iterables and keep the values you need
  • Combinefilter() withmap() andreduce() to approach different problems
  • Replacefilter() withlist comprehensions andgenerator expressions

With this new knowledge, you can now usefilter() in your code to give it afunctional style. You can also switch to a more Pythonic style and replacefilter() withlist comprehensions orgenerator expressions.

Recommended Course

Filtering Iterables With Python(54m)

🐍 Python Tricks 💌

Get a short & sweetPython Trick delivered to your inbox every couple of days. No spam ever. Unsubscribe any time. Curated by the Real Python team.

Python Tricks Dictionary Merge

AboutLeodanis Pozo Ramos

Leodanis is a self-taught Python developer, educator, and technical writer with over 10 years of experience.

» More about Leodanis

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

MasterReal-World Python Skills With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

MasterReal-World Python Skills
With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

What Do You Think?

Rate this article:

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students.Get tips for asking good questions andget answers to common questions in our support portal.


Looking for a real-time conversation? Visit theReal Python Community Chat or join the next“Office Hours” Live Q&A Session. Happy Pythoning!

Keep Learning

Related Topics:intermediatebest-practicespython

Related Learning Paths:

Related Courses:

Related Tutorials:

Keep reading Real Python by creating a free account or signing in:

Already have an account?Sign-In

Almost there! Complete this form and click the button below to gain instant access:

Python Logo

5 Thoughts On Python Mastery

🔒 No spam. We take your privacy seriously.


[8]ページ先頭

©2009-2026 Movatter.jp