Python Tutorial for Beginners 28 – Private methods in Python

///Python Tutorial for Beginners 28 – Private methods in Python

Python Tutorial for Beginners 28 – Private methods in Python

FavoriteLoadingAdd to favorites

In this Python Tutorial for Beginners video I am going to show How to declare Private methods in Python. To create a private method in a class you can use double underscores in front of your member, so you they are made local to the class.

#PythonTutorialforBeginners #ProgrammingKnowledge #LearnPython #PythonCourse
★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ ⚫️
Java Programming Course ➡️ ⚫️
Bash Shell Scripting Course ➡️ ⚫️
Linux Command Line Tutorials ➡️ ⚫️
C Programming Course ➡️ ⚫️
C++ Programming Course ➡️ ⚫️
PHP Programming Course ➡️ ⚫️
Android Development Course ➡️ ⚫️
C# Programming Course ➡️ ⚫️
JavaFx Programming Course ➡️ ⚫️
NodeJs Programming Course ➡️ ⚫️
Jenkins Course For Developers and DevOps ➡️ ⚫️
Scala Programming Tutorial Course ➡️ ⚫️
Bootstrap Responsive Web Design Tutorial ➡️ ⚫️
MongoDB Tutorial Course ➡️ ⚫️
QT C++ GUI Tutorial For Beginners ➡️

★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare –
Data Science – |
Machine Learning – |
Artificial Intelligence – |
MERN Stack E-Degree Program – |
DevOps E-degree – |
Data Analytics with R – |
AWS Certification Training – |
Projects in Java – |
Machine Learning With TensorFlow – |
Angular 8 – Complete Essential Guide –
Kotlin Android Development Masterclass –
Learn iOS Programming Building Advance Projects –

★★★ Follow ★★★
My Website –

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

source

By |2020-02-04T01:38:27+00:00February 4th, 2020|Python Video Tutorials|13 Comments

13 Comments

  1. ProgrammingKnowledge February 4, 2020 at 1:38 am - Reply
  2. Saif Ul Islam February 4, 2020 at 1:38 am - Reply

    Thanks!

  3. rodwynnejones February 4, 2020 at 1:38 am - Reply

    Are private methods/variable inheritable?

  4. Surya Gadde February 4, 2020 at 1:38 am - Reply

    Private variables and private method are hidden. But we can call private variables and private methods in a different way.

    >>> print(hello.__c) —-> Returns error
    >>> print(hello._Hello__c) —> Prints 30

    >>> hello.__private_method() —> Returns error
    >>> hello._Hello__private_method() —-> Prints "Private"

  5. soumilshah1995 February 4, 2020 at 1:38 am - Reply

    Lovely explained great thumbs up

  6. AbdulRaoof Arakkal February 4, 2020 at 1:38 am - Reply

    To access private variable outside the class use: hello._Hello__c …… for example print(hello._Hello__c)

    class Test:
    def __init__(self):
    self.pub1 = 12
    self._single = 33
    self.__double = 44

    t = Test()
    print(t.pub1)
    print(t._single)
    # print(t.__double)
    print(t._Test__double)
    t._Test__double = 55
    print(t._Test__double)

  7. ictdivision bangladesh February 4, 2020 at 1:38 am - Reply

    class Hello:

    def __init__(self,name):

    self.a=10

    self._b=20

    self.__c=30

    def public_method(self):

    print(self.a)

    print(self.__c)

    print("public")

    self.__private_method()

    def __private_method(self):

    print("private")

    hello=Hello("name")

    print(hello.a)

    print(hello._b)

    hello.public_method()

    hello.__private_method()

    output:
    C:UsersIMRANPycharmProjectsuntitled6venvScriptspython.exe C:/Users/IMRAN/.PyCharm2018.3/config/scratches/amirulislam.py

    10

    Traceback (most recent call last):

    20

    File "C:/Users/IMRAN/.PyCharm2018.3/config/scratches/amirulislam.py", line 17, in <module>

    10

    hello.__private_method()

    AttributeError: 'Hello' object has no attribute '__private_method'

    30

    public

    private

    Process finished with exit code 1

  8. Николай Коромыслов February 4, 2020 at 1:38 am - Reply

    Thank you very much! It is super!

  9. Devanand Sharma February 4, 2020 at 1:38 am - Reply

    Nice 🤗

  10. Sam East February 4, 2020 at 1:38 am - Reply

    Your Work is very well Appreciated. Excellent Job! Waiting for the upcoming Videos.

  11. SRGR mohan February 4, 2020 at 1:38 am - Reply

    Nxt php tutorial plz…😘😘😘👌👌👌👌

  12. aman sen February 4, 2020 at 1:38 am - Reply

    Sir Hindi use nhi karte ap ,thodi Hindi bhi use Kiya kro please sir

  13. Madhur Verma February 4, 2020 at 1:38 am - Reply

    Sir muje c language me aache se padne ke liye kya karu notes banane ke Liya kya karu please sir tell me

Leave A Comment

*