Colab

2+3

5
(2+3)*4

20
2*3+4

10
2**8

256
x=10

x<100

True
x<100 and x>=0

True
not x<100

False
x==10

True
x!=10

False
x=10

x="hello"

type(x)

str
x=[1,2,3]

type(x)

list
x=10

s="hello"

s.upper()

'HELLO'
s.upper().lower()

'hello'
"the quick brown fox jumped over the lazy dog".replace("the", "da")

'da quick brown fox jumped over da lazy dog'
'a'

'a'
"a"

'a'
'i enjoy "sarcasm" '

'i enjoy "sarcasm" '
" 'the road to excess ' -- milton "

" 'the road to excess ' -- milton "
lst = [1,2,3]

len(lst)

3
lst.pop()

3
lst

[1, 2]
lst.append("hello")

lst.append(["one", "two", "three"])

lst

[1, 2, 'hello', ['one', 'two', 'three']]
print

<function print>
print(lst)

[1, 2, 'hello', ['one', 'two', 'three']]
backup = print

backup

<function print>
print = 10

print(lst)


    ---------------------------------------------------------------------------

    TypeError                                 Traceback (most recent call last)

    <ipython-input-37-d630a01b856b> in <module>
    ----> 1 print(lst)
    

    TypeError: 'int' object is not callable


print = backup

print(lst)

[1, 2, 'hello', ['one', 'two', 'three']]
backup(lst)

[1, 2, 'hello', ['one', 'two', 'three']]
list = [1,2,3]

z = list()


    ---------------------------------------------------------------------------

    TypeError                                 Traceback (most recent call last)

    <ipython-input-42-5f5e7eaa41f5> in <module>
    ----> 1 z = list()
    

    TypeError: 'list' object is not callable


list = type([])

list()

[]
lst

[1, 2, 'hello', ['one', 'two', 'three']]
lst[0]

1
lst[3]

['one', 'two', 'three']
lst[3][1]

'two'
lst[3][1][0]

't'
d = {"london" : "uk", "jerusalem" : "israel", "paris" : "france"}

d["london"]

'uk'
d["uk"]


    ---------------------------------------------------------------------------

    KeyError                                  Traceback (most recent call last)

    <ipython-input-52-f9eb8d2b2c63> in <module>
    ----> 1 d["uk"]
    

    KeyError: 'uk'


d["washington DC"] = "US"

d.pop("london")

'uk'
d.keys()

dict_keys(['jerusalem', 'paris', 'washington DC'])
d["jerusalem"] = "ohio"

d

{'jerusalem': 'ohio', 'paris': 'france', 'washington DC': 'US'}
d.values()

dict_values(['ohio', 'france', 'US'])
d.items()

dict_items([('jerusalem', 'ohio'), ('paris', 'france'), ('washington DC', 'US')])
t = (1,2,3)

import math

math.sin

<function math.sin>
math.sin(0)

0.0
math.pi

3.141592653589793
dir(math)

['__doc__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'acos',
 'acosh',
 'asin',
 'asinh',
 'atan',
 'atan2',
 'atanh',
 'ceil',
 'copysign',
 'cos',
 'cosh',
 'degrees',
 'e',
 'erf',
 'erfc',
 'exp',
 'expm1',
 'fabs',
 'factorial',
 'floor',
 'fmod',
 'frexp',
 'fsum',
 'gamma',
 'gcd',
 'hypot',
 'inf',
 'isclose',
 'isfinite',
 'isinf',
 'isnan',
 'ldexp',
 'lgamma',
 'log',
 'log10',
 'log1p',
 'log2',
 'modf',
 'nan',
 'pi',
 'pow',
 'radians',
 'sin',
 'sinh',
 'sqrt',
 'tan',
 'tanh',
 'tau',
 'trunc']
dir(backup)

['__call__',
 '__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__name__',
 '__ne__',
 '__new__',
 '__qualname__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__self__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__text_signature__']
dir(lst)

['__add__',
 '__class__',
 '__contains__',
 '__delattr__',
 '__delitem__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getitem__',
 '__gt__',
 '__hash__',
 '__iadd__',
 '__imul__',
 '__init__',
 '__init_subclass__',
 '__iter__',
 '__le__',
 '__len__',
 '__lt__',
 '__mul__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__reversed__',
 '__rmul__',
 '__setattr__',
 '__setitem__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'append',
 'clear',
 'copy',
 'count',
 'extend',
 'index',
 'insert',
 'pop',
 'remove',
 'reverse',
 'sort']