Static variable in Python | Basics

Python Static variables are declared a variable inside a class, but outside the function (method). Static variables are also known as class variables in Python.

Examples Static variable in Python

Simple example code shows that the variables with a value assigned in a class declaration, are static variables.

class MyClass:
    i = "Static Variable"


print(MyClass.i)

Output:

Static variable in Python

Do comment if you have any doubts and suggestions on this Python variable topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.