๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ inner-classes-python
Python Nested & Inner Classes | DataCamp
January 3, 2020 - In this basic Python tutorial, you'll learn about why and when you should use inner classes. ... You have probably heard of the nested functions in Python. If you know what that means then understanding inner/nested classes is nothing.
๐ŸŒ
Amplifyabhi
amplifyabhi.com โ€บ home โ€บ unlocking the power of python nested classes: a comprehensive guide
Unlocking the Power of Python Nested Classes: A Comprehensive Guide - AmplifyAbhi
January 22, 2024 - Learn how it helps organize related tasks in Python. To make a nested class, you just create a new class inside another one.
Discussions

Are nested classes a thing?
No. This is only useful in very rare and advanced scenarios (such as Django's inner Meta classes). The nested class has no special access to the outer class's attribute (unlike in, say, Java) which is why this is rarely useful. However instantiating a normal class as an instance attribute of another class is frequently useful. This is known as composition, and can be used in exactly the way you describe - the key is that the main class would pass itself in as a parameter when instantiating the second one, so that class could store and reference it. For example: class Layer: def __init__(self, viewer): self.viewer = viewer def present(self): # do something with self.viewer class Viewer: def __init__(self): self.layer = Layer(self) More on reddit.com
๐ŸŒ r/learnpython
13
3
July 3, 2022
Is it good practice to use nested classes if the class has a lot of methods?
If you've got a huge number of methods and some are similar, you might be able to combine some of them using optional named parameters. More on reddit.com
๐ŸŒ r/learnpython
4
0
October 9, 2020
Why would I need to nest classes?
Nesting a class inside another isn't really doing anything exotic, it's just defining the inner class in such a way that it's only visible to methods of that class, in the same way that the definition of a local variable defined in a function is only available there. Maybe it's some internal type used for bookkeeping and there's no reason for it to be exposed anywhere outside of that class. Perhaps you're writing a class that manages a series of dates and internally you want to store all the data in some custom date representation. I don't know. A compelling example isn't springing to mind. The point is, if one class is only ever going to be used within another class, and for some reason you don't want to expose it to the rest of the program, then you can define it as a nested class. More on reddit.com
๐ŸŒ r/Python
25
20
December 8, 2013
[Python] Beautiful Soup scraping nested Div

Seems to be working here:

from requests import get
from bs4 import BeautifulSoup

url = 'http://store.steampowered.com/app/343461/?snr=1_7_7_204_150_18'
soup = BeautifulSoup(get(url).text)

print(soup.find_all('div', {'class': 'game_area_details_specs'}))

I'd check to see if you're feeding BeautifulSoup the correct HTML data.

More on reddit.com
๐ŸŒ r/learnprogramming
2
1
March 20, 2015
People also ask

When should I use a nested class?
Use one for a tightly scoped helper type or namespace that should be discovered through the outer class, not merely to hide a large unrelated abstraction.
๐ŸŒ
pythonpool.com
pythonpool.com โ€บ home โ€บ tutorials โ€บ nested classes in python: inner classes and design choices
Nested Classes in Python: Inner Classes and Design Choices
Can Python classes be defined inside other classes?
Yes. The inner class becomes an attribute of the outer class and can be accessed through that namespace.
๐ŸŒ
pythonpool.com
pythonpool.com โ€บ home โ€บ tutorials โ€บ nested classes in python: inner classes and design choices
Nested Classes in Python: Inner Classes and Design Choices
What is an alternative to nested classes?
A module-level class, composition, a dataclass, or a private helper often makes dependencies and testing clearer.
๐ŸŒ
pythonpool.com
pythonpool.com โ€บ home โ€บ tutorials โ€บ nested classes in python: inner classes and design choices
Nested Classes in Python: Inner Classes and Design Choices
๐ŸŒ
Medium
medium.com โ€บ @staytechrich โ€บ python-intermediate-004-nested-classes-061a2d7287da
Python Intermediate_004_ Nested Classes | by CodeAddict | Medium
January 12, 2025 - Letโ€™s begin with a simple example using two separate classes and then explore how the same functionality can be achieved with nested classes. Letโ€™s take a real-world example of a School and its Students: # Two separate classes class Student: def __init__(self, name, age): self.name = name self.age = age def introduce(self): return f"My name is {self.name}, and I am {self.age} years old." class School: def __init__(self, name): self.name = name self.students = [] def add_student(self, student): self.students.append(student) def display_students(self): print(f"Students in {self.name}:") for student in self.students: print(student.introduce()) # Usage school = School("Greenwood High") student1 = Student("Alice", 15) student2 = Student("Bob", 16) school.add_student(student1) school.add_student(student2) school.display_students()
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ nested class in python
Nested Class in Python | Delft Stack
October 10, 2023 - Note that we cannot access the inner class directly. We create its object using the outer.inner format. We can access the nested class in the outer class but not the other way around.
๐ŸŒ
Celery-Q
celeryq.org โ€บ home โ€บ python โ€บ mastering pythonโ€™s class nesting: a deep dive
Nested Classes Python: A Comprehensive Guide - Celery-Q
September 20, 2023 - In this tutorial, we delved into the concept of inner (nested) classes within Python, gaining a comprehensive understanding of their nature, purpose, and the techniques for effectively integrating them into our codebase to enhance its structural ...
๐ŸŒ
Medium
medium.com โ€บ @teamcode20233 โ€บ python-nested-class-a-comprehensive-guide-f3b64ede49ee
Python Nested Class: A Comprehensive Guide | by Teamcode | Medium
May 25, 2023 - In Python, a nested class is a class defined inside another class. This allows the outer class to access the inner class, and vice versa. To declare a nested class, you simply define it inside the outer class.
๐ŸŒ
Python Pool
pythonpool.com โ€บ home โ€บ tutorials โ€บ nested classes in python: inner classes and design choices
Nested Classes in Python: Inner Classes and Design Choices
July 13, 2026 - Most classes should stay at module level because they are easier to import, test, and reuse. Use nesting only when the relationship is clear, such as a parser with small token types, a report with internal section objects, or a widget with private configuration helpers. The official Python tutorial on classes is the best starting point for the broader class model.
Find elsewhere
๐ŸŒ
Pythonspot
pythonspot.com โ€บ inner-classes
Python Inner Class โ€” Tutorial with Examples | Pythonspot
January 1, 2026 - Related Course: Practice Python with interactive exercises ยท We create a class (Human) with one inner class (Head). An instance is created that calls a method in the inner class: ... def __init__(self): self.name = 'Guido' self.head = self.Head() ...
๐ŸŒ
Lightly-dev
lightly-dev.com โ€บ blog โ€บ python-nested-class
Python Nested Class Tutorial by Lightly
May 23, 2023 - In Python, a nested class is a class defined inside another class. This allows the outer class to access the inner class, and vice versa. To declare a nested class, you simply define it inside the outer class.
๐ŸŒ
PyShark
pyshark.com โ€บ home โ€บ inner (nested) classes in python
Inner (Nested) Classes in Python - Python Programming - PyShark
January 4, 2024 - In this tutorial we explore inner (nested) classes in Python, what they are, why and how we use them to create more structured code.
๐ŸŒ
Novixys Software
novixys.com โ€บ blog โ€บ nested-inner-classes-python
Nested or Inner Classes in Python | Novixys Software Dev Blog
December 1, 2018 - Since the interface to the Cats class did not change, there is no change in the client code. a = Cats() a.add('joe').add('jack').add('fink').add('dink') for c in a: print c ยท Python does have support for nested or inner classes.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Learn Python NESTED CLASSES in 9 minutes! ๐Ÿ“› - YouTube
# Nested class = A class defined within another class# class Outer:# class Inner:# Benefits: Allows you to logically group...
Published: June 21, 2024
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_class_inner.asp
Python Inner Classes
An inner class is a class defined inside another class. The inner class can access the properties and methods of the outer class.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_inner_classes.htm
Python - Inner Classes
Organization Name: Tutorials Point In Department 1 In Department 2 ยท It refers to an inner class that itself contains another inner class. It creates multiple levels of nested classes.
๐ŸŒ
Cpucademy
cpucademy.github.io โ€บ python-nested-classes.html
Nested classes
class BankAccount: def __init__(self, balance): self.__balance = balance # private attribute def getBalance(self): return self.__balance def updateBalance(self, amount): self.__balance += amount def start(self, interestRate): self.__interest = self.Interest(interestRate, self) class Interest: # nested / inner class def __init__(self, interestRate, bankacc): self.__interestRate = interestRate # private attribute bankacc.updateBalance((bankacc.getBalance() * self.__interestRate) / 100) bankacc = BankAccount(1000) print(bankacc.getBalance()) bankacc.start(5) print(bankacc.getBalance())
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ inheritance-in-python-inner-class
Inheritance in Python Inner Class | GeeksforGeeks
January 30, 2020 - It is transitive in nature, which means that if class B inherits from another class A, then all the subclasses of B would automatically inherit from class A. To use inheritance in the inner class, consider the below code snippet.
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-nested-class
Python Nested Classes: A Comprehensive Guide - CodeRivers
February 22, 2026 - Consider alternative designs: Before ... top-level class might be a cleaner solution. Python nested classes provide a powerful way to organize code, encapsulate related functionality, and manage namespaces....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ inner-class-in-python
Inner Class in Python - GeeksforGeeks
July 15, 2025 - A class defined in another class is known as an inner class or nested class. If an object is created using child class means inner class then the object can also be used by parent class or root class.