{"id":431,"date":"2020-10-10T10:14:38","date_gmt":"2020-10-10T10:14:38","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=431"},"modified":"2025-03-28T01:31:47","modified_gmt":"2025-03-28T01:31:47","slug":"python-private-attributes","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/python-oop\/python-private-attributes\/","title":{"rendered":"Python Private Attributes"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about encapsulation and how to use private attributes to accomplish encapsulation in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-encapsulation-in-python'>Introduction to encapsulation in Python <a href=\"#introduction-to-encapsulation-in-python\" class=\"anchor\" id=\"introduction-to-encapsulation-in-python\" title=\"Anchor for Introduction to encapsulation in Python\">#<\/a><\/h2>\n\n\n\n<p>Encapsulation is one of the four fundamental concepts in object-oriented programming including abstraction, encapsulation, inheritance, and polymorphism.<\/p>\n\n\n\n<p>Encapsulation is the packing of data and <a href=\"https:\/\/www.pythontutorial.net\/python-basics\/python-functions\/\">functions<\/a> that work on that data within a single object. By doing so, you can hide the internal state of the object from the outside. This is known as <strong>information hiding<\/strong>.<\/p>\n\n\n\n<p>A <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-class\/\">class<\/a> is an example of encapsulation. A class bundles data and methods into a single unit. And a class provides the access to its attributes via methods.<\/p>\n\n\n\n<p>The idea of information hiding is that if you have an attribute that isn&#8217;t visible to the outside, you can control the access to its value to make sure your object is always has a valid state.<\/p>\n\n\n\n<p>Let&#8217;s take a look at an example to better understand the encapsulation concept.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='python-encapsulation-example'>Python encapsulation example <a href=\"#python-encapsulation-example\" class=\"anchor\" id=\"python-encapsulation-example\" title=\"Anchor for Python encapsulation example\">#<\/a><\/h2>\n\n\n\n<p>The following defines the <code>Counter<\/code> class:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Counter<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current = <span class=\"hljs-number\">0<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">increment<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current += <span class=\"hljs-number\">1<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">value<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">return<\/span> self.current\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">reset<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current = <span class=\"hljs-number\">0<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>Counter<\/code> class has one attribute called <code>current<\/code> which defaults to zero. And it has three methods: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>increment()<\/code> increases the value of the <code>current<\/code> attribute by one.<\/li>\n\n\n\n<li><code>value()<\/code> returns the current value of the <code>current<\/code> attribute<\/li>\n\n\n\n<li><code>reset()<\/code> sets the value of the <code>current<\/code> attribute to zero.<\/li>\n<\/ul>\n\n\n\n<p>The following creates a new instance of the <code>Counter<\/code> class and calls the <code>increment()<\/code> method three times before showing the current value of the counter to the screen:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Counter<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current = <span class=\"hljs-number\">0<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">increment<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current += <span class=\"hljs-number\">1<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">value<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">return<\/span> self.current\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">reset<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current = <span class=\"hljs-number\">0<\/span>\n\n\ncounter = Counter()\n\n\ncounter.increment()\ncounter.increment()\ncounter.increment()\n\nprint(counter.value())\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pythontutorial.net\/playground\/?q=Y2xhc3MgQ291bnRlcjoKICAgIGRlZiBfX2luaXRfXyhzZWxmKToKICAgICAgICBzZWxmLmN1cnJlbnQgPSAwCgogICAgZGVmIGluY3JlbWVudChzZWxmKToKICAgICAgICBzZWxmLmN1cnJlbnQgKz0gMQoKICAgIGRlZiB2YWx1ZShzZWxmKToKICAgICAgICByZXR1cm4gc2VsZi5jdXJyZW50CgogICAgZGVmIHJlc2V0KHNlbGYpOgogICAgICAgIHNlbGYuY3VycmVudCA9IDAKCgpjb3VudGVyID0gQ291bnRlcigpCgoKY291bnRlci5pbmNyZW1lbnQoKQpjb3VudGVyLmluY3JlbWVudCgpCmNvdW50ZXIuaW5jcmVtZW50KCkKCnByaW50KGNvdW50ZXIudmFsdWUoKSk%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-number\">3<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It works perfectly fine but has one issue. <\/p>\n\n\n\n<p>From the outside of the <code>Counter<\/code> class, you still can access the current attribute and change it to whatever you want. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Counter<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current = <span class=\"hljs-number\">0<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">increment<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current += <span class=\"hljs-number\">1<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">value<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">return<\/span> self.current\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">reset<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self.current = <span class=\"hljs-number\">0<\/span>\n\ncounter = Counter()\n\ncounter.increment()\ncounter.increment()\ncounter.current = <span class=\"hljs-number\">-999<\/span>\n\nprint(counter.value())\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pythontutorial.net\/playground\/?q=Y2xhc3MgQ291bnRlcjoKICAgIGRlZiBfX2luaXRfXyhzZWxmKToKICAgICAgICBzZWxmLmN1cnJlbnQgPSAwCgogICAgZGVmIGluY3JlbWVudChzZWxmKToKICAgICAgICBzZWxmLmN1cnJlbnQgKz0gMQoKICAgIGRlZiB2YWx1ZShzZWxmKToKICAgICAgICByZXR1cm4gc2VsZi5jdXJyZW50CgogICAgZGVmIHJlc2V0KHNlbGYpOgogICAgICAgIHNlbGYuY3VycmVudCA9IDAKCmNvdW50ZXIgPSBDb3VudGVyKCkKCmNvdW50ZXIuaW5jcmVtZW50KCkKY291bnRlci5pbmNyZW1lbnQoKQpjb3VudGVyLmN1cnJlbnQgPSAtOTk5CgpwcmludChjb3VudGVyLnZhbHVlKCkp\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-number\">-999<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, we create an instance of the <code>Counter<\/code> class, call the <code>increment()<\/code> method twice and set the value of the current attribute to an invalid value <code>-999<\/code>. <\/p>\n\n\n\n<p>So how do you prevent the <code>current<\/code> attribute from modifying outside of the <code>Counter<\/code> class?<\/p>\n\n\n\n<p>That&#8217;s why private attributes come into play.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='private-attributes'>Private attributes <a href=\"#private-attributes\" class=\"anchor\" id=\"private-attributes\" title=\"Anchor for Private attributes\">#<\/a><\/h2>\n\n\n\n<p>Private attributes can be only accessible from the methods of the class. In other words, they cannot be accessible from outside of the class.<\/p>\n\n\n\n<p>Python doesn&#8217;t have a concept of private attributes. In other words, all attributes are accessible from the outside of a class.<\/p>\n\n\n\n<p>By convention, you can define a private attribute by prefixing a single underscore (_):<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">_attribute<\/code><\/span><\/pre>\n\n\n<p>This means that the _attribute should not be manipulated and may have a breaking change in the future.<\/p>\n\n\n\n<p>The following redefines the <code>Counter<\/code> class with the <code>current<\/code> as a private attribute by convention:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Counter<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self._current = <span class=\"hljs-number\">0<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">increment<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self._current += <span class=\"hljs-number\">1<\/span>\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">value<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">return<\/span> self._current\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">reset<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        self._current = <span class=\"hljs-number\">0<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='name-mangling-with-double-underscores'>Name mangling with double underscores <a href=\"#name-mangling-with-double-underscores\" class=\"anchor\" id=\"name-mangling-with-double-underscores\" title=\"Anchor for Name mangling with double underscores\">#<\/a><\/h2>\n\n\n\n<p>If you prefix an attribute name with double underscores (<code>__<\/code>) like this: <\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">__attribute<\/code><\/span><\/pre>\n\n\n<p>Python will automatically change the name of the <code>__attribute<\/code> to:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">_class__attribute<\/code><\/span><\/pre>\n\n\n<p>This is called the <strong>name mangling<\/strong> in Python.<\/p>\n\n\n\n<p>By doing this, you cannot access the <code>__attribute<\/code> directly from the outside of a class like:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">instance<\/span><span class=\"hljs-selector-class\">.__attribute<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>However, you still can access it using the <code>_class__attribute name<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">instance<\/span><span class=\"hljs-selector-class\">._class__attribute<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following example redefines the <code>Counter<\/code> class with the <code>__current<\/code> attribute:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">class Counter:\n    def __init__(self):\n        self.__current = 0\n\n    def increment(self):\n        self.__current += 1\n\n    def value(self):\n        return self.__current\n\n    def reset(self):\n        self.__current = 0\n<\/code><\/span><\/pre>\n\n\n<p>Now, if you attempt to access __current attribute, you&#8217;ll get an error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">counter = Counter()\n<span class=\"hljs-keyword\">print<\/span>(counter.__current)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">AttributeError: <span class=\"hljs-string\">'Counter'<\/span> object has no attribute <span class=\"hljs-string\">'__current'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>However, you can access the <code>__current<\/code> attribute as <code>_Counter___current<\/code> like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">counter = Counter()\n<span class=\"hljs-keyword\">print<\/span>(counter._Counter__current)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Encapsulation is the packing of data and methods into a class so that you can hide the information and restrict access from outside.<\/li>\n\n\n\n<li>Prefix an attribute with a single underscore (<code>_<\/code>) to make it private by convention. <\/li>\n\n\n\n<li>Prefix an attribute with double underscores (<code>__<\/code>) to use the name mangling.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"431\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-oop\/python-private-attributes\/\"\n\t\t\t\tdata-post-title=\"Python Private Attributes\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"431\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-oop\/python-private-attributes\/\"\n\t\t\t\tdata-post-title=\"Python Private Attributes\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn about the encapsulation and how to use private attributes to accomplish encapsulation in Python<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":417,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-431","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=431"}],"version-history":[{"count":2,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/431\/revisions"}],"predecessor-version":[{"id":7298,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/431\/revisions\/7298"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/417"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}