Pytho1 Merged

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

In [1]: 5+3

8
Out[1]:

In [6]: 5//2

2
Out[6]:

In [1]: 7-8

-1
Out[1]:

In [2]: 4*-1

-4
Out[2]:

In [7]: 5%2

1
Out[7]:

In [ ]: 1**8

In [3]: 2+2

4
Out[3]:

In [4]: 3**2

9
Out[4]:

In [1]: 12345*4

49380
Out[1]:

In [4]: 12345**82

317884776440926673316071144851267647505713184000319533419755476728729105289309145704229294603789231584874559943732064673188194277677922822925225294346846070500060102317287246920101
Out[4]:
014103953447930169920339992337607012463791675200187266268128397859578982107088447500892836467449524011782166664692207691533809565953561104834079742431640625

In [2]: 3/2

1.5
Out[2]:

In [5]: 2+2*5

12
Out[5]:

In [8]: 'hELP'

'hELP'
Out[8]:

In [9]: 2+3;3+3

6
Out[9]:

In [10]: "hELLO"

'hELLO'
Out[10]:

In [12]: 1+2, "Hello"

(3, 'Hello')
Out[12]:

In [13]: "Heal" + "Lord"

'HealLord'
Out[13]:

In [14]: "Heal" - "al"

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [14], in <cell line: 1>()
----> 1 "Heal" - "al"

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

In [20]: 'A123'+'123'

'A123123'
Out[20]:

In [24]: print (3+2); 3-2

5
1
Out[24]:

In [34]: d=1+5
e=3+4
d

6
Out[34]:

In [ ]:

In [ ]:
In [1]: type(90.89)

float
Out[1]:

In [2]: type(9)

int
Out[2]:

In [3]: type("sdf")

str
Out[3]:

In [4]: type(Telegram)

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 type(Telegram)

NameError: name 'Telegram' is not defined

In [5]: int 12

Input In [5]
int 12
^
SyntaxError: invalid syntax

In [6]: name="print"
nam=print
a=8
b=2,2
print(name)
print(nam)
print(a)
print(b)

print
<built-in function print>
8
(2, 2)

In [7]: name="print"
nam="printad"
a=8
b=2.2
print(name)
print(nam)
print(a)
print(b)

print
printad
8
2.2

In [22]: name="print"
nam="printad"
a=8
b=2.2
print(name, "\t and \t" , nam, "\n" ,a, "\n" , b) #use comma

print and printad


8
2.2

In [9]: name="print"
nam="printad"
a=8
b=2.2
print("name:", name, "\n" "number:" ,a)

name: print
number: 8

In [10]: type("true")

str
Out[10]:

In [11]: nam1="Heal"
nam2=" the World"
print(nam1+nam2)

Heal the World

In [21]: v='123'
x=float(v)
y=int(v)
print(x, "\n", y) #use comma

123.0
123

In [19]: x=1;y=2;
print(x+y)
print(x-y)
print(x*y)
print(x/y)
print(x%y)
print(x**y)

3
-1
2
0.5
1
1

In [25]: #Area of rectange l=10, b=20

l=10; b=20;
print("area of rectangle:\t=" , l*b)

area of rectangle: = 200

In [29]: #sum of numbers


n=10;m=8;
print("Sum:\n=",l+b)

Sum:
= 30

In [34]: #enter name and age


n=input("enter your name") #input
a=input("enter age")
print(n, a)

enter your nameThomas


enter age23
Thomas 23

In [39]: #Square of num


n=int (input("enter number:")) #use int of input as n becomes str by default Converting string ti interger
print("square=\t", n*n)

enter number:5
square= 25

In [ ]: Converting string ti interger


In [15]: a=10;b=5;
sum=a+b
print ("sum of %d and %d is %d" %(a,b,sum))

sum of 10 and 5 is 15

In [20]: side=6.0;
area=side*side;
print("Area of the square of side %f = %f" %(side,area))#%f because the area is in float format

Area of the square of side 6.000000 = 36.000000

In [23]: side=6.0;
area=side*side;
print("Area of the square of side %f = %f" %(side,area))#%f because the area is in float format
print("Area of the square of side", side, "=", area)

Area of the square of side 6.000000 = 36.000000


Area of the square of side 6.0 = 36.0

In [30]: name="abc"; regno=123; M1=21; M2=32;


name2="bcd"; regno2=234; M3=42; M4=20;
print("Name: %s regno: %d M1: %d M2: %d" %(name, regno, M1, M2))
print("Name: %s regno: %d M3: %d M4: %d" %(name2, regno2, M3, M4))

Name: abc regno: 123 M1: 21 M2: 32


Name: bcd regno: 234 M3: 42 M4: 20

In [35]: #dot
print('{0},{2},{1}'.format("Maria","Kerala",562001))

Maria,562001,Kerala

In [37]: #dot
print('{0},{1},{other}'.format("Maria","Kerala",other=562001))

Maria,Kerala,562001

In [39]: n="tom"
reg=123456;
print('my name and reg is:{} and {}'.format(n,reg))

my name and reg is:tom and 123456

In [41]: print("name{0}, batch{1:d}, per{2:0.2f}".format('rahul',2021,71.3000)) #d for int, f for float, 2:0 2 decimal place

namerahul, batch2021, per71.30

In [ ]:

In [ ]:

You might also like