In [5]:
def sq(a, x):
    while True:
        print(x)
        y = (x + a/x) / 2
        if y == x:
            break
        x = y
    return x

In [7]:
sq(4,30)


30
15.066666666666666
7.666076696165192
4.093927989455537
2.535492372645326
2.0565476126560274
2.0007774272954872
2.000000151039589
2.0000000000000058
2.0
Out[7]:
2.0

In [8]:
l = [23,43,55]

In [9]:
for idx, val in enumerate(l):
    print(idx, val)


0 23
1 43
2 55

In [20]:
t = ['a','b','c','d','e','f']

In [21]:
t[1:3] = ['x','y','z']

In [22]:
t


Out[22]:
['a', 'x', 'y', 'z', 'd', 'e', 'f']

In [23]:
t


Out[23]:
['a', 'x', 'y', 'z', 'd', 'e', 'f']

In [24]:
ll = [1,2]

In [26]:
ll.append(3)

In [27]:
ll


Out[27]:
[1, 2, 3]

In [28]:
ll = ['a','b']

In [29]:
sum(ll)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-29-11cabd66443f> in <module>()
----> 1 sum(ll)

TypeError: unsupported operand type(s) for +: 'int' and 'str'

In [30]:
ll = ['a','a']

In [31]:
ll


Out[31]:
['a', 'a']

In [32]:
ll.remove('a')

In [33]:
ll


Out[33]:
['a']

In [34]:
a = '11'

In [35]:
la = list(a)

In [36]:
la


Out[36]:
['1', '1']

In [44]:
a = "abc"

In [45]:
"-".join(list(a))


Out[45]:
'a-b-c'

In [47]:
from  functools import reduce

In [48]:
reduce(lambda x,y: x+y, [1,2,3])


Out[48]:
6

In [49]:
def redu(x, y):
    result = 0
    if x == y:
        result += (x+y)
    else:
        result += x
    return result

In [51]:
reduce(redu, [1,1])


Out[51]:
2

In [54]:
",".join(list("abcde"))


Out[54]:
'a,b,c,d,e'

In [55]:
str(['a','b'])


Out[55]:
"['a', 'b']"

In [57]:
''.join(['a',1])


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-57-6a4370fcfd7d> in <module>()
----> 1 ''.join(['a',1])

TypeError: sequence item 1: expected str instance, int found

In [61]:
''.join(list(map(lambda x: str(x),['a',1])))


Out[61]:
'a1'

In [62]:
print('\x1b[6;30;42m' + 'Success!' + '\x1b[0m')


Success!

In [66]:
list(range(10,0,-1))


Out[66]:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

In [67]:
a = [1,2,3]

In [68]:
a[:]


Out[68]:
[1, 2, 3]

In [69]:
a[:30]


Out[69]:
[1, 2, 3]

In [90]:
def upper_str(str):
    result = ""
    for i in str:
        result += (chr(ord(i) - 32))
    return result

In [91]:
upper_str('abc')


Out[91]:
'ABC'

In [92]:
-5 is -5


Out[92]:
True

In [93]:
-6 is -6


Out[93]:
False

In [94]:
'banana'.maketrans('an','oh')


Out[94]:
{97: 111, 110: 104}

In [ ]: