# gautamakash91/session2

a year ago
In [3]:
``a= ["abc","xyz","asd"] ``
In [4]:
``id(a)``
Out[4]:
``4579408224``
In [5]:
``a[0]``
Out[5]:
``'abc'``
In [6]:
``a[0]="req"``
In [7]:
``a``
Out[7]:
``['req', 'xyz', 'asd']``
In [8]:
``id(a)``
Out[8]:
``4579408224``
In [9]:
``[3,4,5]b = "xyz"``
In [10]:
``id(b)``
Out[10]:
``4579301552``
In [11]:
``b = "pop"``
In [12]:
``id(b)``
Out[12]:
``4539647792``
In [13]:
``arr = [5,6,7]``
In [14]:
``sum(arr)``
Out[14]:
``18``
In [15]:
``ar = []``
In [16]:
``ar``
Out[16]:
``[]``
In [19]:
``ar.append(9)``
In [20]:
``ar``
Out[20]:
``[5, 9]``
In [21]:
``sum(ar)``
Out[21]:
``14``
In [22]:
``3**2``
Out[22]:
``9``
In [28]:
``a= input("enter number of rows")``
```enter number of rows4 ```
In [29]:
``a``
Out[29]:
``'4'``
In [33]:
``````val = "1"
ar = []

for i in range(int(a)):
ar.append(val)
val = val+"1"

for j in ar:
print(int(j)**2)``````
```1 121 12321 1234321 ```
In [34]:
``d = [5,3,2,7,8,9,3,2,1]``
In [35]:
``print(d)``
```[5, 3, 2, 7, 8, 9, 3, 2, 1] ```
In [36]:
``d``
Out[36]:
``[5, 3, 2, 7, 8, 9, 3, 2, 1]``
In [37]:
``d[:]``
Out[37]:
``[5, 3, 2, 7, 8, 9, 3, 2, 1]``
In [38]:
``d[4:]``
Out[38]:
``[8, 9, 3, 2, 1]``
In [39]:
``d[:4]``
Out[39]:
``[5, 3, 2, 7]``
In [43]:
``d[6:2:-1]``
Out[43]:
``[3, 9, 8, 7]``
In [42]:
``d[::-1]``
Out[42]:
``[1, 2, 3, 9, 8, 7, 2, 3, 5]``
In [45]:
``````i=0
while i<10:
print(i)
i=i+1``````
```0 1 2 3 4 5 6 7 8 9 ```
In [48]:
``j = {"a":1,"b":2,"c":3}``
In [49]:
``j``
Out[49]:
``{'a': 1, 'b': 2, 'c': 3}``
In [52]:
``j["b"]``
Out[52]:
``2``
In [53]:
``people = [{"name":"Akash", "age":18},{"name":"Gautam","age":18}]``
In [59]:
``people[0]["name"]``
Out[59]:
``'Akash'``
In [60]:
``people.append({"name":"Modi","age":55})``
In [61]:
``people``
Out[61]:
``````[{'name': 'Akash', 'age': 18},
{'name': 'Gautam', 'age': 18},
{'name': 'Modi', 'age': 55}]``````
In [62]:
``arr = ["a","b","c"]``
In [63]:
``arr``
Out[63]:
``['a', 'b', 'c']``
In [65]:
``arr``
Out[65]:
``['a', 'b', 'c']``
In [66]:
``br = {"a":1,"b":2,"c":3}``
In [68]:
``br["b"]``
Out[68]:
``2``
In [77]:
``````num = int(input("how many inputs do you want?"))
arr = []
for i in range(num):
name = input("enter name")
age = int(input("enter age"))
arr.append({"name":name,"age":age})

smallest = arr[0]
largest = arr[0]
s = 0

for i in arr:
if i["age"] > largest["age"]:
largest = i
if i["age"] < smallest["age"]:
smallest = i
s = s+i["age"]

print("Youngest person is {}".format(smallest["name"]))
print("Oldest person is {}".format(largest["name"]))
print("average age is {}".format(s/len(arr)))``````
```how many inputs do you want?2 enter nameAkash enter age18 enter nameGautam enter age20 Youngest person is Akash Oldest person is Gautam average age is 19.0 ```
In [82]:
``````f = 12
print("hello!! {t} is the value of f. f: {t}".format(t=f))``````
```hello!! 12 is the value of f. f: 12 ```
In [79]:
``print("the value of f is: ",f)``
```the value of f is: 12 ```
In [95]:
``h = [[1,[5,{"k":3}]],[{"h":3},[4,5]],[[8,2],{"g": 5}]]``
In [111]:
``h[0][1][1]["k"]``
Out[111]:
``3``
In [113]:
``k = {"0":{"1":[7,4,2] },"1":[{"0":4},0,{"2":"g"}]}``
In [114]:
``k``
Out[114]:
``{'0': {'1': [7, 4, 2]}, '1': [{'0': 4}, 0, {'2': 'g'}]}``
In [120]:
``k["1"][2]["2"]``
Out[120]:
``'g'``
In [122]:
``k["0"]["1"][1]``
Out[122]:
``4``
In [1]:
``import jovian``
In [ ]:
``jovian.commit()``
```[jovian] Saving notebook.. ```
In [ ]:
`` ``