Python Practice2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

.

>>> name='gautam'
>>> id(name)
53114944
>>> num=777
>>> id(num)
53149520
>>> a=8
>>> b=a
>>> a
8
>>> b
8
>>> id(a)
1939396896
>>> id(b)
1939396896
>>> id(8)
1939396896
>>> y=8
>>> id(y)
1939396896
>>> a=33
>>> id(a)
1939397296
>>> id(b)
1939396896
>>> y=a
>>> id(y)
1939397296
>>> b=10
>>> id(b)
1939396928
>>> PI=3.14
>>> PI
3.14
>>> PI=3.17
>>> PI
3.17
>>> type(PI)
<class 'float'>
>>>
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 'data type in python
SyntaxError: EOL while scanning string literal
>>> name=[none,numeric,list,tuple,set,string,range,dectionary]
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
name=[none,numeric,list,tuple,set,string,range,dectionary]
NameError: name 'none' is not defined
>>> 'none'
'none'
>>> numeric=['int','float','complex', 'bool']
>>> num=3.8
>>> type(num)
<class 'float'>
>>> num=8
>>> type(num)
<class 'int'>
>>> num=3+8j
>>> type(num)
<class 'complex'>
>>> a=7.9
>>> b=int(a)
>>> type(b)
<class 'int'>
>>> b
7
>>> k=float(b)
>>> k
7.0
>>> c=complex(k,b)
>>> type(c)
<class 'complex'>
>>> c
(7+7j)
>>> k>=b
True
>>> bool=k<b
>>> type(bool)
<class 'bool'>
>>> bool
False
>>> int(False)
0
>>> int(True)
1
>>> lst=[76,87,98,56]
>>> type(lst)
<class 'list'>
>>> lst
[76, 87, 98, 56]
>>> s={34,64,45,88,23}
>>> type(s)
<class 'set'>
>>> s
{64, 34, 45, 23, 88}
>>> t=(76,9,90,89,56)
>>> type(t)
<class 'tuple'>
>>> t
(76, 9, 90, 89, 56)
>>> st='gautam'
>>> type(st)
<class 'str'>
>>> st
'gautam'
>>> range(8)
range(0, 8)
>>> list(range(8))
[0, 1, 2, 3, 4, 5, 6, 7]
>>> list(range(1,8,2))
[1, 3, 5, 7]
>>> type(range(8))
<class 'range'>
>>> d={'bitu':'mi6','kittu':'note4','happu':'guru'}
>>> d.keys(['bitu','kittu','happu'])
Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
d.keys(['bitu','kittu','happu'])
TypeError: keys() takes no arguments (1 given)
>>> d.keys()
dict_keys(['bitu', 'kittu', 'happu'])
>>> d.valuse()
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
d.valuse()
AttributeError: 'dict' object has no attribute 'valuse'
>>> d.valuses()
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
d.valuses()
AttributeError: 'dict' object has no attribute 'valuses'
>>> d.values()
dict_values(['mi6', 'note4', 'guru'])
>>> d['happu']
'guru'
>>> d.get('kittu')
'note4'
>>> "OPERATORS IN PYTHON"
'OPERATORS IN PYTHON'
>>> "ARITHMETIC"
'ARITHMETIC'
>>> x=4
>>> y=8
>>> x+y
12
>>> y-x
4
>>> x/y
0.5
>>> y//x
2
>>> x%y
4
>>> x*y
32
>>> x=x+7
>>> x
11
>>> x+=7
>>> x
18
>>> x-=9
>>> x
9
>>> x*=5
>>> x
45
>>> a,b=6,7
>>> a
6
>>> b
7
>>> "unary"
'unary'
>>> n=12
>>> n
12
>>> -n
-12
>>> n=-n
>>> n
-12
>>> n
-12
>>> -n
12
>>> -n
12
>>> n
-12
>>> a>b
False
>>> a<b
True
>>> a==b
False
>>> a=9
>>> a==b
False
>>> a
9
>>> b
7
>>> a=7
>>> a==b
True
>>> a>=b
True
>>> a<=
SyntaxError: invalid syntax
>>> a<=b
True
>>> a!=b
False
>>> b=9
>>> a!=b
True
>>> "logical"
'logical'
>>> ('And,Or,Not')
'And,Or,Not'
>>> x=8
>>> b=6
>>> x>9 and b<9
False
>>> x<9 and b<9
True
>>> x>7 or b>7
True
>>> x<5 or b>9
False
>>> x=True
>>> x
True
>>> not x
False
>>> x
True
>>> x=not x
>>> x
False
>>>

You might also like