-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_types2.py
98 lines (64 loc) · 1.74 KB
/
data_types2.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
"""Data types2.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1qwsy7cnT48IxhEJm3L8czFfH2jDN_ior
"""
temp = 5
print(temp, "is of type", type(temp))
Size = 2.0
print(Size, "is of type", type(Size))
complexNum = 1+2j
print(a, "is complex number?", isinstance(1+2j,complexNum))
temp = [5,10,15,20,25,30,35,40]
# temp[2] = 15
print("a[2] = ", temp[2])
# temp[0:3] = [5, 10, 15]
print("temp[0:3] = ", temp[0:3])
# temp[5:] = [30, 35, 40]
print("temp[5:] = ", temp[5:])
a = [1, 2, 3]
a[2] = 4 # mutable
print(a)
str1 = 'Hello world!'
# str1[4] = 'o'
print("str1[4] = ", str1[4])
# str1[6:11] = 'world'
print("str1[6:11] = ", str1[6:11])
# Generates error
# Strings are immutable in Python
str1[5] ='d'
test = {5,2,3,1,4}
# printing set variable
print("test = ", test)
# data type of variable a
print(type(test))
sample = {1,2,3}
print(sample[1]) # does not work
dict1 = {1:'value','key':4}
print(type(dict1))
print("dict1[1] = ", dict1[1])
print("dict1['key'] = ", dict1['key'])
float(5)
int(10.6)
float('2.5')
str(25)
var_int = 123
var_float = 1.23
var_new = var_int + var_float
print("datatype of var_int:",type(var_int))
print("datatype of var_float:",type(var_float))
print("Value of num_new:",var_new)
print("datatype of var_new:",type(var_new))
var_int = 300
var_str = "500"
print(var_int + var_str)
num_int = 500
num_str = "390"
print("Data type of num_int:",type(num_int))
print("Data type of num_str before Type Casting:",type(num_str))
num_str = int(num_str)
print("Data type of num_str after Type Casting:",type(num_str))
num_sum = num_int + num_str
print("Sum of num_int and num_str:",num_sum)
print("Data type of the sum:",type(num_sum))