Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python’s @classmethod decorator makes the class itself the method’s implicit first argument, conventionally named cls. That lets a method use class-level information or create an instance of whichever class called it—including a subclass. Use an instance method when you need a particular object, a class method when you need the class, and a static method when neither implicit argument is needed.

What does @classmethod do?

The Python built-in functions documentation defines a class method as one that receives the class as an implicit first argument, just as an instance method receives an instance. By convention, that argument is named cls.

Decorate a function inside a class with @classmethod to make it a class method. You can call it through the class or through an instance. In either case, Python supplies the class—not the instance—as the first argument. If a derived class makes the call, Python supplies that derived class.

class User:
    @classmethod
    def guest(cls):
        return cls("guest", is_active=True)

    def __init__(self, name, is_active):
        self.name = name
        self.is_active = is_active

user = User.guest()

Here, cls is User, so cls("guest", is_active=True) creates a User instance. Calling guest through an instance is also allowed, but that instance is not passed to the method; its class is.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

How to use a class method as an alternate constructor

An alternate constructor accepts a different representation of the data, converts or validates it, and returns a new instance. Use cls(...) when the constructor should create an instance of the class used for the call rather than always creating one fixed base class.

Example: construct from an ISO-style date string

class DateParts:
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day

    @classmethod
    def from_iso(cls, text):
        year, month, day = map(int, text.split("-"))
        return cls(year, month, day)

For example, calling DateParts.from_iso("2026-10-05") passes DateParts as cls, and the method returns an instance created from the parsed values. The example splits the string and converts each part to an integer; it does not perform comprehensive calendar validation.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Why use cls instead of the base-class name?

If a subclass inherits from_iso and calls it, Python passes the subclass as cls. The constructor call therefore creates an instance of that subclass, provided its initializer accepts the supplied arguments. Hard-coding DateParts(...) would instead always construct the base class.

This dynamic binding is useful beyond custom constructors. The Python descriptor guide illustrates it with a Dict.fromkeys class method that creates and populates an instance using cls(), allowing the calling class to determine the result’s type.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Class method vs. instance method vs. static method

Method kind Implicit first argument Use it when
Instance method The instance, conventionally self The operation needs or changes per-object state.
Class method The class, conventionally cls The operation needs class-level information or should construct the class used for the call.
Static method None The function belongs conceptually in the class namespace but needs neither an instance nor a class argument.

The descriptor guide describes class-method binding as supplying the object’s type when accessed through an object, or the class itself when accessed through a class. A static method passes through without adding an implicit argument. The practical distinction is that cls is dynamically bound, which is what makes subclass-aware construction possible; a static method has no such class argument.

Common classmethod mistakes

  • Naming the first parameter self. The parameter is the class object, not an instance. Use the conventional name cls to make that clear.
  • Hard-coding the base class in a polymorphic constructor. If subclasses should get instances of their own type, return cls(...) rather than BaseClass(...).
  • Using a class method for a helper that needs no class behavior. A plain function or static method may communicate the intent more clearly when no implicit class argument is needed.
  • Calling an instance method through the class without supplying an instance. An instance method expects its instance argument. Use a class method only when the operation genuinely belongs to the class rather than to one object.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Python version notes for class methods and descriptors

Python’s documented behavior has changed for class methods that wrap other descriptors, such as properties. The current built-in functions reference and descriptor guide record these relevant milestones:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • Python 3.9: Class methods could wrap other descriptors.
  • Python 3.10: Class methods began inheriting metadata attributes such as __module__, __name__, __qualname__, __doc__, and __annotations__, and gained __wrapped__.
  • Python 3.11: Wrapping other descriptors with classmethod was deprecated.
  • Python 3.13: That descriptor-wrapping support was removed.

For current Python code, do not rely on a stacked @classmethod and @property pattern. The built-in reference documents classmethod as a descriptor that transforms a method into a class method; it is not a general-purpose way to make a class-level property.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Choosing the right method type

  • Choose an instance method if the behavior depends on the state of one object.
  • Choose a class method if the behavior needs the class or should create an instance of the class through which it was called.
  • Choose a static method if the function logically belongs in the class but needs neither an instance nor the class.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.