0

Python supports functions and variables directly in a .py file. So I need not have a class under which these are placed.

Are these functions and variables static? What is the Python terminology for this?

In Python methods can be static methods or class methods. Can variables be static variables or class variables in Python or are they the same thing?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Raj
  • 1
  • 1
  • [This](https://stackoverflow.com/questions/68645/static-class-variables-and-methods-in-python) might help? – lancylot2004 Aug 15 '22 at 17:14
  • 2
    Since you are talking about variables and functions _outside_ a class, the term "static" does not really apply here. Those are simply functions and variables in the "global" scope (of the module they are defined in) or in the scope of a module (if that module is imported). – tobias_k Aug 15 '22 at 17:16
  • I would generally call such functions "module functions", or simply "functions" (with no qualifier, I generally assume a function is independent and *not* on a class). I would call such variables "module variables", or "module constants" if constant. Obviously, non-constant module variables should generally be avoided since that's only a stone's toss from a global variable. – Silvio Mayolo Aug 15 '22 at 17:20
  • If you want a metaphor by saying that a module is a class, then functions in those modules are like static methods since they have neither `self` nor `cls` as their first parameter. – quamrana Aug 15 '22 at 17:21
  • `In Python methods can be static methods or class methods.` also instance methods; a static method is not the same thing as an instance method and a class method is not the same thing as an instance method or a static method. – Random Davis Aug 15 '22 at 17:29

0 Answers0