-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-types.py
More file actions
executable file
·81 lines (59 loc) · 1.31 KB
/
data-types.py
File metadata and controls
executable file
·81 lines (59 loc) · 1.31 KB
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
#!/usr/bin/python
############################################
# #
# Program: data-types.py #
# Author: Asanka Sayakkara #
# Description: #
# This script demonstrates the basic #
# data types available on python. #
# #
############################################
import cmath # for complex number mathematics
print("==Data Types==")
a = 45
print(type(a))
c = [10, 32, 49]
print(type(c))
print("A string to a float")
a = '23.86'
print(type(a))
a = float(a)
print(type(a))
# Dealing with complex numbers
print("Complex Numbers")
b = 2 + 3j
print(type(b))
print(b.real)
print(b.imag)
print(dir(cmath))
c = cmath.sqrt(b)
print(c)
# Handling lists
print("Processing lists")
mylist1 = [23, 43, 56, 62, 40]
mylist2 = [93, 39, 48]
print(mylist1)
print(mylist2)
newlist = mylist1 + mylist2
print(newlist)
newlist.append(100)
print(newlist)
newlist.remove(62)
print(newlist)
print("Range starting from 1 to less than 10")
print(range(1, 10))
print("Range from 1 to less than 10 in 2 value steps")
print(range(1, 10, 2))
for i in range(0, 10):
print(i)
# slicing a list
print("Slicing Lists")
mylist = range(1, 21)
print(mylist)
print(mylist[0:10])
print(mylist[0:10:2])
print(mylist[1:10:2])
print("Odd places in the list")
print(mylist[0::2])
print("Even places in the list")
print(mylist[1::2])