<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Built-in Data Types
Python has built-in support for a number of data types, like boolean, integer, float and complex numbers, as well as strings.
Here we'll show a few examples of how to use them.
The bool type
Boolean values are used to represent truth values. Booleans can have only two values
Step1:  Comparing things returns a bool
Step2:  The result of a comparison can be stored in a variable and we can use it to do other things
Step3:  Caution! Please!
Step4:  Anything can be converted to a boolean
Step5:  Please uncomment the line below to see the full docummentation for the bool type.
Step6:  The int type
Interger numbers are implemented by the int type. Unlike other programming languages, in Python integers have virtually infinite precision.
Step7:  What operations are supported by an int?
Step8:  Those '__xxx__' methods are called Python's magic methods.
They are magic in the sense that Python will call them implicitly when you use the corresponding operator.
Some of those methods are a bit advanced, though, and we'll leave it as an exercise to you to learn how to use them.
Let's begin with the basic arithmetic operations.
Arithmetic operators
|operator|magic method  |meaning|
|--------|--------------|-------|
|+     |__add__     |addition|
|-     |__sub__     |subtraction|
|*     |__mul__     |multiplication|
|/     |__truediv__ |division|
|%     |__mod__     |remainder after division|
|//    |__floordiv__|truncated division|
|**    |__pow__     |to the power of|
|abs   |__abs__     |absolute value of|
Step9:  Comparison operators
|operator|magic method|meaning|
|--------|------------|-------|
|==    |__eq__    |is equal to|
|!=    |__ne__    |is not equal to|
|&lt;     |__lt__    |is less than|
|&gt;     |__gt__    |is greater than|
|&lt;=    |__le__    |is less than or equal to|
|&gt;=    |__ge__    |is greater than or equal to|
Step10:  Conversion to/from an int
Step11:  Calling some attributes and methods
Step12:  Please uncomment the line below to see the full docummentation for the int type.
Step13:  The float type
Real numbers are implemented by the float type. Like all programming languages, a float is just an approximation to the true value of a real number. This limitation is imposed by the hardware. In Python there is no single precision float! Here all floats are 64-bit accurate, i.e., double precision.
Step14:  What operations are supported by a float?
Step15:  Arithmetic operators
|operator|magic method  |meaning|
|--------|--------------|-------|
|+     |__add__     |addition|
|-     |__sub__     |subtraction|
|*     |__mul__     |multiplication|
|/     |__truediv__ |division|
|%     |__mod__     |remainder after division|
|//    |__floordiv__|truncated division|
|**    |__pow__     |to the power of|
|abs   |__abs__     |absolute value of|
Step16:  Comparison operators
|operator|magic method|meaning|
|--------|------------|-------|
|==    |__eq__    |is equal to|
|!=    |__ne__    |is not equal to|
|&lt;     |__lt__    |is less than|
|&gt;     |__gt__    |is greater than|
|&lt;=    |__le__    |is less than or equal to|
|&gt;=    |__ge__    |is greater than or equal to|
Step17:  Conversion to/from a float
Step18:  Calling some attributes and methods
Step19:  Please uncomment the line below to see the full docummentation for the float type.
Step20:  The complex type
TODO
The str type
A string is a sequence of characters. You can define a string in four different ways
Step22:  What operations are supported by a str?
Step23:  Comparison operators
|operator|magic method|meaning|
|--------|------------|-------|
|==    |__eq__    |is equal to|
|!=    |__ne__    |is not equal to|
|&lt;     |__lt__    |is less than|
|&gt;     |__gt__    |is greater than|
|&lt;=    |__le__    |is less than or equal to|
|&gt;=    |__ge__    |is greater than or equal to|
Step24:  Remember! String comparison uses lexicographical ordering. Lexicographical ordering for strings uses the Unicode code point number to order individual characters. However...
...most of times what you may want to compare is the length of strings!
Step25:  Concatenating strings
Step26:  Check if a string contains a sub-string
Step27:  Build a string of N identical sub-strings
Step28:  Methods lower, upper and capitalize
Step29:  Split a string into sub-strings
Step30:  Check if a string starts or ends with a sub-string
Step31:  Strings are immutable
Step32:  Using the replace method
Step33:  replace all occurrences
Step34:  replace the first 4 occurrences
Step35:  replace the last 5 occurrences
Step36:  Please uncomment the line below to see the full docummentation for the str type.
<ASSISTANT_TASK:>
Python Code:
type(True)
type(False)
Explanation: Built-in Data Types
Python has built-in support for a number of data types, like boolean, integer, float and complex numbers, as well as strings.
Here we'll show a few examples of how to use them.
The bool type
Boolean values are used to represent truth values. Booleans can have only two values: True or False.
The bool type is defined as a special case of an int, which in such case can only have two possible values, 1 or 0, i.e., True or False.
End of explanation
True == True
True == False
False == False
5 == 5
5 == 7
5 != 7
5 > 3
-1 < 0
1 > 0
3.14 > 2.72
3.14 <= 2.72
'Hello!' != 'Hello!'
'Hi!' != 'Hello!'
[1, 2, 3] == [1, 2, 3]
[1, 2, 3] == [4, 5]
Explanation: Comparing things returns a bool
End of explanation
x = 5 == 7
y = 3 != 0
print(x, y)
z = x or y  # Either x or y is True? Yes!
print(z)
z = x and y  # Both x and y are True? No!
print(z)
Explanation: The result of a comparison can be stored in a variable and we can use it to do other things
End of explanation
myvar = 5   # Points myvar to object 5
myvar == 3  # Check if myvar is equal to 3
x = True     # Here x points to a bool
y = "True"   # Here y points to a str
# z = true   # This is an error!!! Here z is undefined.
Explanation: Caution! Please!
End of explanation
bool(True)  # Duh!
bool(False)  # Duh!
bool(0)
bool(5)
bool(-15)
bool(0.0)
bool(3.14)
bool('')  # Is there anything in this string? No!
bool('Hello')  # Is there anything in this string? Yes!
bool([])  # Is there anything in this list? No!
bool([1, 2, 3])  # Is there anything in this list? Yes!
bool(print)  # Even a function can be converted to a boolean.
             # But why would you do that?
             # Well, Python gives you the power!
             # You just have to learn how to use it! ;-)
Explanation: Anything can be converted to a boolean
End of explanation
# help(bool)
Explanation: Please uncomment the line below to see the full docummentation for the bool type.
End of explanation
type(42)
b = 42
print(b)
Explanation: The int type
Interger numbers are implemented by the int type. Unlike other programming languages, in Python integers have virtually infinite precision.
End of explanation
print(dir(int))
Explanation: What operations are supported by an int?
End of explanation
print('+\t', 29 + 3)
print('-\t', 29 - 3)
print('*\t', 29 * 3)
print('/\t', 29 / 3)
print('%\t', 29 % 3)
print('//\t', 29 // 3)
print('**\t', 29**3)
print('abs()\t', abs(-1))
Explanation: Those '__xxx__' methods are called Python's magic methods.
They are magic in the sense that Python will call them implicitly when you use the corresponding operator.
Some of those methods are a bit advanced, though, and we'll leave it as an exercise to you to learn how to use them.
Let's begin with the basic arithmetic operations.
Arithmetic operators
|operator|magic method  |meaning|
|--------|--------------|-------|
|+     |__add__     |addition|
|-     |__sub__     |subtraction|
|*     |__mul__     |multiplication|
|/     |__truediv__ |division|
|%     |__mod__     |remainder after division|
|//    |__floordiv__|truncated division|
|**    |__pow__     |to the power of|
|abs   |__abs__     |absolute value of|
End of explanation
print('==\t', 1 == 2)
print('!=\t', 1 != 2)
print('<\t', 1 < 2)
print('>\t', 1 > 2)
print('<=\t', 1 <= 2)
print('>=\t', 1 >= 2)
Explanation: Comparison operators
|operator|magic method|meaning|
|--------|------------|-------|
|==    |__eq__    |is equal to|
|!=    |__ne__    |is not equal to|
|&lt;     |__lt__    |is less than|
|&gt;     |__gt__    |is greater than|
|&lt;=    |__le__    |is less than or equal to|
|&gt;=    |__ge__    |is greater than or equal to|
End of explanation
print(int(42))           # __int__          int to int (Duh!)
print(bool(42))          # __bool__         int to bool
print(int(True))         # __int__          bool to int
print(int(3.14))         # __int__          float to int
print(float(42))         # __float__        int to float
print(str(42))           # __str__          int to str
# print(int("Hi!"))      # ERROR!!!         str to int is not supported!
print(42)                # __str__ is implicitly called by print()
Explanation: Conversion to/from an int
End of explanation
i = 42
print(i.real, i.imag)
print(i.numerator, i.denominator)
i = 2**63 - 1   # On 64-bit systems, this is the maximum integer number allowed on most programming languages.
print(i)        # This limitation is imposed by the hardware.
i.bit_length()  # Number of bits necessary to represent it in binary.
                # The extra bit is for the sign, so 1+63 == 64-bits.
i = 111**222    # In Python integer numbers are implemented in software.
print(i)        # So, they have virtually infinite precision.
i.bit_length()  # That's why it's possible to have very very very large ints. The only
                # limitation is given by how much RAM memory you have installed on your machine.
Explanation: Calling some attributes and methods
End of explanation
# help(int)
Explanation: Please uncomment the line below to see the full docummentation for the int type.
End of explanation
type(3.14)
b = 3.14
print(b)
Explanation: The float type
Real numbers are implemented by the float type. Like all programming languages, a float is just an approximation to the true value of a real number. This limitation is imposed by the hardware. In Python there is no single precision float! Here all floats are 64-bit accurate, i.e., double precision.
End of explanation
print(dir(float))
Explanation: What operations are supported by a float?
End of explanation
print('+\t', 10.71 + 3)
print('-\t', 10.71 - 3)
print('*\t', 10.71 * 3)
print('/\t', 10.71 / 3)
print('%\t', 10.71 % 3)
print('//\t', 10.71 // 3)
print('**\t', 10.71 ** 3)
print('abs()\t', abs(-1.0))
Explanation: Arithmetic operators
|operator|magic method  |meaning|
|--------|--------------|-------|
|+     |__add__     |addition|
|-     |__sub__     |subtraction|
|*     |__mul__     |multiplication|
|/     |__truediv__ |division|
|%     |__mod__     |remainder after division|
|//    |__floordiv__|truncated division|
|**    |__pow__     |to the power of|
|abs   |__abs__     |absolute value of|
End of explanation
print('==\t', 3.14 == 5)
print('!=\t', 3.14 != 5)
print('<\t', 3.14 < 5)
print('>\t', 3.14 > 5)
print('<=\t', 3.14 <= 5)
print('>=\t', 3.14 >= 5)
Explanation: Comparison operators
|operator|magic method|meaning|
|--------|------------|-------|
|==    |__eq__    |is equal to|
|!=    |__ne__    |is not equal to|
|&lt;     |__lt__    |is less than|
|&gt;     |__gt__    |is greater than|
|&lt;=    |__le__    |is less than or equal to|
|&gt;=    |__ge__    |is greater than or equal to|
End of explanation
print(float(3.14))       # __float__        float to float (Duh!)
print(bool(3.14))        # __bool__         float to bool
print(float(True))       # __float__        bool to float
print(int(3.14))         # __int__          float to int
print(float(42))         # __float__        int to float
print(str(3.14))         # __str__          float to str
# print(float("Hi!"))    # ERROR!!!         str to float is not supported!
print(3.14)              # __str__ is implicitly called by print()
Explanation: Conversion to/from a float
End of explanation
x, y = 3.14, 5.0
print(x.real, x.imag)
print(x.is_integer())         # Is 3.14 == int(3.14)? No!
print(y.is_integer())         # Is 5.0 == int(5.0)? Yes!
print(x.as_integer_ratio())
print(y.as_integer_ratio())
Explanation: Calling some attributes and methods
End of explanation
# help(float)
Explanation: Please uncomment the line below to see the full docummentation for the float type.
End of explanation
type('Hello')
s = 'Hello'
print(s)
Explanation: The complex type
TODO
The str type
A string is a sequence of characters. You can define a string in four different ways:
'Hello'
"Hello"
'''Hello'''
Hello
Any of those forms is valid in Python, but try not mix them.
Of course, all rules have an exception, p.ex.:
bad:
'you don't know'
better:
'you don\'t know'
best:
"you don't know"
In which case is okay to mix them.
Anyway, whatever format you choose to use just be consistent in you code!
End of explanation
print(dir(str))
Explanation: What operations are supported by a str?
End of explanation
print('==\t', 'Hi' == 'Hello')
print('!=\t', 'Hi' != 'Hello')
print('<\t', 'Hi' < 'Hello')      # Humm... what's happening here?
print('>\t', 'Hi' > 'Hello')      # Humm... what's happening here?
print('<=\t', 'Hi' <= 'Hello')    # Humm... what's happening here?
print('>=\t', 'Hi' >= 'Hello')    # Humm... what's happening here?
# String comparison uses lexicographical ordering: first the first two items
# are compared, and if they differ this determines the outcome of the comparison.
# If they are equal, the next two items are compared, and so on, until either
# sequence is exhausted.
print(ord('H'), ord('i'))
print(ord('H'), ord('e'), ord('l'), ord('l'), ord('o'))
help(ord)
ord('H') < ord('H') or ord('i') < ord('e')  # A-Ha!!! Now we know what happened there!
ord('H') > ord('H') or ord('i') > ord('e')
ord('H') <= ord('H') and ord('i') <= ord('e')
ord('H') >= ord('H') and ord('i') >= ord('e')
Explanation: Comparison operators
|operator|magic method|meaning|
|--------|------------|-------|
|==    |__eq__    |is equal to|
|!=    |__ne__    |is not equal to|
|&lt;     |__lt__    |is less than|
|&gt;     |__gt__    |is greater than|
|&lt;=    |__le__    |is less than or equal to|
|&gt;=    |__ge__    |is greater than or equal to|
End of explanation
print(len('Hi'), len('Hello'), len('abracadabra'))
print('==\t', len('Hi') == len('Hello'))
print('!=\t', len('Hi') != len('Hello'))
print('<\t', len('Hi') < len('Hello'))
print('>\t', len('Hi') > len('Hello'))
print('<=\t', len('Hi') <= len('Hello'))
print('>=\t', len('Hi') >= len('Hello'))
help(len)
Explanation: Remember! String comparison uses lexicographical ordering. Lexicographical ordering for strings uses the Unicode code point number to order individual characters. However...
...most of times what you may want to compare is the length of strings!
End of explanation
x = 'Py'
y = 'thon'
z = 'is'
w = 'ok!'
print(x + y + z + w)
print(x + y + ' ' + z + ' ' + w)
x = 'Py'
y = 'thon '   # Note the white space
z = 'is '     # Note the white space
w = 'nice!'
print(x + y + z + w)
x = 'Py'
y = 'thon'
z = 'is'
w = 'awesome!'
print(' '.join([x + y, z, w]))
print(' -*- '.join([x + y, z, w]))
Explanation: Concatenating strings
End of explanation
s = 'Python -*- is -*- awesome!'
'-*-' in s
'Python' in s
'Hello' in s
s in s   # Duh!
Explanation: Check if a string contains a sub-string
End of explanation
'Ha ' * 5
'Ha ' * 5 + 'Ha!!!'
Explanation: Build a string of N identical sub-strings
End of explanation
s = 'aWeSoMe!'
print(s.lower(), s.upper(), s.capitalize())
Explanation: Methods lower, upper and capitalize
End of explanation
s = 'Python -*- is -*- awesome -*- and -*- I -*- love -*- it!'
print(s)
print(s.split(' '))
print(s.split('-*-'))
s.split('-*-', 1)  # split by at most 1 time.
s.split('-*-', 3)  # split by at most 3 times.
help(str.split)
Explanation: Split a string into sub-strings
End of explanation
print(s)
s.startswith('Py')
s.startswith('Python')
s.startswith('awesome')
s.endswith('!')
s.endswith('it!')
s.endswith('and')
Explanation: Check if a string starts or ends with a sub-string
End of explanation
S = 'Pithon'
#    -^----
#    012345
# S[1] = 'y'     # This is an ERROR! You can not change the content of a string!
Explanation: Strings are immutable
End of explanation
# It will return a copy of S with all occurrences
# of substring old replaced by new.
ss = S.replace('i', 'y')
print(S)
print(ss)
S = 'Hi! How are you?'
ss = S.replace('Hi!', 'Hello!')
print(S)
print(ss)
Explanation: Using the replace method
End of explanation
S = 'tattarrattat' + ' # ' + 'abracadabra'
ss = S.replace('a', '-')
print(S)
print(ss)
Explanation: replace all occurrences
End of explanation
S = 'tattarrattat' + ' # ' + 'abracadabra'
ss = S.replace('a', '-', 4)
print(S)
print(ss)
Explanation: replace the first 4 occurrences
End of explanation
S = 'tattarrattat' + ' # ' + 'abracadabra'
ss = S
ss = ''.join(reversed(ss))
ss = ss.replace('a', '-', 5)
ss = ''.join(reversed(ss))
print(S)
print(ss)
Explanation: replace the last 5 occurrences
End of explanation
# help(str)
Explanation: Please uncomment the line below to see the full docummentation for the str type.
End of explanation
<END_TASK>