Is there any public and private functions in python class like C

I want to know whether there is any public and private functions in Python Class like C

such that private functions from outside access cannot be done

In Python, it is not possible to mark private class members in a way such that the interpreter restricts the access to it. There is a convention to mark private members with one or two leading underscores. The idea is that members with one underscore are also meant to be used by subclasses (like protected variables in C++), while members with two leading underscores are not meant to be used by subclasses (like private variables in C++).

This is also the reason for name mangling: If there are two leading underscores, the compiler applies a name mangling scheme - not to actually prevent the access, but to avoid naming conflicts if the same name is used in a subclass.

>>> class C:
...     def __init__(self):
...        self._a=1
...        self.__b=2
... 
>>> 
>>> c=C()
>>> c._a
1
>>> c._C__b
2

In C there are - as in Python - no private or protected struct members either. Also there, everything is done by convention.

A language that actually has private and protected class members is C++. But even there, it is not impossible to access private class members. The following code would work and print “1, 3” in all standard compilers.

#include <iostream>

class C {
public:
    C(int a, int b) : m_a(a), m_b(b) {}
    void print() { std::cout << m_a << ", " << m_b << std::endl; }    
private:
    int m_a, m_b;
};

int main()
{
    C c(1,2);
    *(((int*)(&c))+1) = 3;
    c.print();
}

If you’re prepared to get into a little obscure template trickery, you don’t even have to reason about object layout in C++ - litb's Blog: Access to private members. That's easy!

(of course this is somewhat off-topic for a Python forum…)

If you just use python, it is impossible. However, if you write C extern, you can create the C class so that python code cannot visit something private in it (even the instance of the class cannot be created in python)