Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Python doesn't have (or need) "parameterized classes", so it's hard to provide examples of them in Python;-). A metaclass is simply "the class of a class": normally <code>type</code> (as long, in Py2, as you remember to make the class new-style by inheriting from <code>object</code>, or some other built-in type or other new-style class -- old-style classes are a legacy artefact in Py2, fortunately disappeared in Py3, and you should ideally just forget about them). You can make a custom metaclass (usually subclassing <code>type</code>) for several advanced purposes, but it's unlikely that you'll ever <em>need</em> to (esp. considering that, since python 2.6, much of what used to require a custom metaclass can now be done more simply with a class decorator).</p> <p>Given any class C, <code>type(C)</code> is its metaclass.</p> <p>A parameterized class is a completely different concept. Closest you can come to it in Python is probably a factory function that makes and returns a class based on its arguments:</p> <pre><code>def silly(n): class Silly(object): buh = ' '.join(n * ['hello']) return Silly Silly1 = silly(1) Silly2 = silly(2) a = Silly1() print(a.buh) b = Silly2() print(b.buh) </code></pre> <p>will print</p> <pre><code>hello hello hello </code></pre> <p>Again, it's definitely <strong>not</strong> something you'll need often — making several classes that differ just by one or a few arguments. Anyway, as you can see, it has absolutely nothing to do with the classes' class (AKA metaclass), which is always <code>type</code> in this example (and in almost every more realistic example I could think of — I just chose to give a simple example, where the point of doing this is hard to discern, rather than a realistic and therefore necessarily very complex one ;-).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload