Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (1.6k points)

I have this example in C/C++ and I want the same code for Python

void numbers()


    static int count = 0;


    printf("count is %d\n", count);


How to implement static member at a function level as opposed to the class level?If I place a function into a class will it change anything?

1 Answer

0 votes
by (25.1k points)

You can add attributes to a function, and use it as a static variable.

def function():

  function.counter += 1


function.counter = 0

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories