forked from navinreddy20/Python-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11 Data Types in Python
74 lines (73 loc) · 1.33 KB
/
11 Data Types in Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Code
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> num = 2.5
>>> type(num)
<class 'float'>
>>> num = 5
>>> type(num)
<class 'int'>
>>> num = 6+9j
>>> type(num)
<class 'complex'>
>>> a = 5.6
>>> b = int(a)
>>> type(b)
<class 'int'>
>>> b
5
>>> k = float(b)
>>> k
5.0
>>> k = 6
>>> c = complex(b,k)
>>> c
(5+6j)
>>> b<k
True
>>> boll = b < k
>>> bool
<class 'bool'>
>>> b > k
False
>>> int(True)
1
>>> int(False)
0
>>> 1st = [25,36,45,12]
SyntaxError: invalid syntax
>>> lst = [25,36,45,12]
>>> type(lst)
<class 'list'>
>>> s = {25,36,45,15,12,25}
>>> s
{36, 12, 45, 15, 25}
>>> type(s)
<class 'set'>
>>> t = (25,36,4,57,12)
>>> type(t)
<class 'tuple'>
>>> str = "navin"
>>> st = 'a'
>>> type(st)
<class 'str'>
>>> range(10)
range(0, 10)
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(2,10,2))
[2, 4, 6, 8]
>>> type(range(10))
<class 'range'>
>>> d = {'navin':'samsung','rahul':'Iphone','kiran':'Oneplus'}
>>> d
{'navin': 'samsung', 'rahul': 'Iphone', 'kiran': 'Oneplus'}
>>> d.keys()
dict_keys(['navin', 'rahul', 'kiran'])
>>> d.values()
dict_values(['samsung', 'Iphone', 'Oneplus'])
>>> d['rahul']
'Iphone'
>>> d.get('kiran')
'Oneplus'
>>>