<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.itcollege.ee/index.php?action=history&amp;feed=atom&amp;title=Advanced_Python_%28Fall_2017%29%2Flecture7</id>
	<title>Advanced Python (Fall 2017)/lecture7 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.itcollege.ee/index.php?action=history&amp;feed=atom&amp;title=Advanced_Python_%28Fall_2017%29%2Flecture7"/>
	<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Advanced_Python_(Fall_2017)/lecture7&amp;action=history"/>
	<updated>2026-06-21T22:57:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Advanced_Python_(Fall_2017)/lecture7&amp;diff=125101&amp;oldid=prev</id>
		<title>Eroman: Created page with &quot;= Lecture 7 =  Data types  == Data type things to know ==  clases in python describe datatype, and when called, create a new object of that type. &lt;code&gt;type&lt;/code&gt; returns the...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Advanced_Python_(Fall_2017)/lecture7&amp;diff=125101&amp;oldid=prev"/>
		<updated>2017-10-23T22:14:25Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Lecture 7 =  Data types  == Data type things to know ==  clases in python describe datatype, and when called, create a new object of that type. &amp;lt;code&amp;gt;type&amp;lt;/code&amp;gt; returns the...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Lecture 7 =&lt;br /&gt;
&lt;br /&gt;
Data types&lt;br /&gt;
&lt;br /&gt;
== Data type things to know ==&lt;br /&gt;
&lt;br /&gt;
clases in python describe datatype, and when called, create a new object of that type. &amp;lt;code&amp;gt;type&amp;lt;/code&amp;gt; returns the datatype &amp;lt;code&amp;gt;isinstance&amp;lt;/code&amp;gt; check if object is an instance of the class&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;In [3]: class A:&lt;br /&gt;
   ...:     pass&lt;br /&gt;
   ...:&lt;br /&gt;
&lt;br /&gt;
In [4]: type(A)&lt;br /&gt;
Out[4]: type&lt;br /&gt;
&lt;br /&gt;
In [5]: type(int)&lt;br /&gt;
Out[5]: type&lt;br /&gt;
&lt;br /&gt;
In [6]: int(10)&lt;br /&gt;
Out[6]: 10&lt;br /&gt;
&lt;br /&gt;
In [7]: float(10)&lt;br /&gt;
 Out[7]: 10.0&lt;br /&gt;
&lt;br /&gt;
In [8]: isinstance(10, int)&lt;br /&gt;
Out[8]: True&lt;br /&gt;
&lt;br /&gt;
In [9]: isinstance(10, float)&lt;br /&gt;
Out[9]: False&lt;br /&gt;
&lt;br /&gt;
In [10]: class MyInt(int):&lt;br /&gt;
    pass&lt;br /&gt;
   ....:&lt;br /&gt;
&lt;br /&gt;
In [11]: a = MyInt(10)&lt;br /&gt;
&lt;br /&gt;
In [12]: a&lt;br /&gt;
Out[12]: 10&lt;br /&gt;
&lt;br /&gt;
In [13]: type(a)&lt;br /&gt;
Out[13]: __main__.MyInt&lt;br /&gt;
&lt;br /&gt;
In [14]: isinstance(a, int)&lt;br /&gt;
Out[14]: True&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Magic Methods ==&lt;br /&gt;
&lt;br /&gt;
there are prefixed and suffixed with &amp;#039;__&amp;#039;, sometimes called &amp;#039;dunder&amp;#039; for &amp;#039;double underscore&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
They define specific python functionality.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class A:&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def __str__(self):&lt;br /&gt;
        return &amp;#039;I am an instance of A&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
a = A()&lt;br /&gt;
print(a.__str__())&lt;br /&gt;
print(str(a))&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Task 1 ===&lt;br /&gt;
&lt;br /&gt;
Make an integer which is: equal to both 5, 6 and the actual number (itself) greater than 3 less than 2&lt;br /&gt;
&lt;br /&gt;
=== Solution ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;from unittest import TestCase&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyInt(int):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Define some magic methods!&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __lt__(self, x):&lt;br /&gt;
        if x == 2:&lt;br /&gt;
            return True&lt;br /&gt;
        else:&lt;br /&gt;
            return super().__lt__(x)&lt;br /&gt;
&lt;br /&gt;
    def __gt__(self, x):&lt;br /&gt;
        if x == 3:&lt;br /&gt;
            return True&lt;br /&gt;
        else:&lt;br /&gt;
            return super().__gt__(x)&lt;br /&gt;
&lt;br /&gt;
    def __eq__(self, x):&lt;br /&gt;
        if x == 5 or x == 6:&lt;br /&gt;
            return True&lt;br /&gt;
        else:&lt;br /&gt;
            return super().__eq__(x)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyIntTestCase(TestCase):&lt;br /&gt;
    def test_gt(self):&lt;br /&gt;
        a = MyInt(1)&lt;br /&gt;
        self.assertTrue(a &amp;gt; 3)&lt;br /&gt;
&lt;br /&gt;
    def test_lt(self):&lt;br /&gt;
        a = MyInt(100)&lt;br /&gt;
        self.assertTrue(a &amp;lt; 2)&lt;br /&gt;
&lt;br /&gt;
    def test_eq(self):&lt;br /&gt;
        a = MyInt(1)&lt;br /&gt;
        self.assertTrue(a == 5)&lt;br /&gt;
        self.assertTrue(a == 6)&amp;lt;/source&amp;gt;&lt;br /&gt;
```&lt;/div&gt;</summary>
		<author><name>Eroman</name></author>
	</entry>
</feed>