0% found this document useful (0 votes)
9 views3 pages

6th Sem Da Parth2

Data algorithms notes

Uploaded by

gamingprotype12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

6th Sem Da Parth2

Data algorithms notes

Uploaded by

gamingprotype12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CODE BY ANANYA DUBEY

In [1]:
x = 10
y = x + 5
print(y)
15

In [11]:
a,b,c=5,6,7
print(a,b,c)
5 6 7

In [12]:
s1 ="Hello"
s2 = "World"
print(s1+s2)
HelloWorld

In [13]:
z = 3.7
print(type(z))
<class 'float'>

In [8]:
l1 = [1, 2, 3]
print(l1)
l1.append(4)
print(l1)
[1, 2, 3]
[1, 2, 3, 4]

In [9]:
tup = (1, 2, 3)
tup[0] = 4
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[9], line 2
1 tup = (1, 2, 3)
----> 2 tup[0] = 4

TypeError: 'tuple' object does not support item assignment

as tuple is immutable so the tuple once created cannot me modified afterwards, here we had tried to modify the value of tuple

In [17]:
d1 = {'a': 1, 'b': 2}
print(d1['b'])
2

In [19]:
s='123'
s1=int(s)
print(s1)
print(type(s1))
123
<class 'int'>

In [20]:
15 % 4
Out[20]:
3

In [22]:
(True or False) and not (False and True)
Out[22]:
True

In [23]:
s="python"
s.upper()
Out[23]:
'PYTHON'
'PYTHON'

In [24]:
l2 = [0, 1, 2, 3, 4, 5]
l2[1:4]
Out[24]:
[1, 2, 3]

In [26]:
d2={'c': 3}
d1.update(d2)
print(d1)
{'a': 1, 'b': 2, 'c': 3}

None keyword is used to define a null value, or no value,False in Boolean,an empty string

In [27]:
print(0.1 + 0.2 == 0.3)
False

The above value comes false because internally python converts the float info value as 0.1000004 to precise it's calculations this happens when
the number is converted from decimal to binary

In [29]:
s="Hello I m Saakar,I have {0} Audi's and {1} BMW's in GTA Vice City".format(10,20)
print(s)
Hello I m Saakar,I have 10 Audi's and 20 BMW's in GTA Vice City

In [57]:
def squares(a, b):
return [ n*n for n in range(a, b+1) ]
print(squares(1,5))
[1, 4, 9, 16, 25]

In [31]:
for key in d1:
print(key)
a
b
c

In [32]:
print("Hello" + 5)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[32], line 1
----> 1 print("Hello" + 5)

TypeError: can only concatenate str (not "int") to str

in the above line of code the 5 is in int ,if it was in string then it could have concenate with hello

In [34]:
def add_two_numbers(a,b):
return (a+b)
a=int(input("Enter The number"))
b=int(input("Enter The number"))
print(add_two_numbers(a,b))
24

In [54]:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1.union(set2))
{1, 2, 3, 4, 5}

In [55]:
student_info = {
'name': 'Saakar Talwar','age': 21,'courses': ['Math', 'Science', 'History']
}

print(student_info)
{'name': 'Saakar Talwar', 'age': 21, 'courses': ['Math', 'Science', 'History']}

In [44]:
s="Python"
s[4]
Out[44]:
'o'

In [49]:
n=int(input("Enter The number to check"))
if n%15==0:
a=True
else:
a= False
print(a)
False

In [53]:
my_list=[1,2,3,4,5]
print(my_list)
my_list.append(6)
print(my_list)
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]

In [ ]:

You might also like