-
Notifications
You must be signed in to change notification settings - Fork 0
/
foo.py
115 lines (92 loc) · 2.01 KB
/
foo.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
print("foo")
a=1+2+3+\
4+5+6+\
7+8+9+10
print(a)
colors=["red","blue","green","yellow","orange","black","white"]
print(colors)
print(colors[0])
a=1;b=2;c=3
lenColors = len(colors)
for i in range(lenColors):
color = colors[i]
print(color)
print("*****************************")
for i in range(100):
print("---------------" + str(i) + "--------------------")
for n in colors:
print(n)
print("")
# Variable assignment
print("Variable assignment")
a = 5
b = 3.2
c = "Hello"
print("a=" + str(a) + " b=" + str(b) + " c=" + c)
print("")
# Multiple assignments
print("Multiple assignments")
a, b, c = 5, 3.2, "Hello"
print("a=" + str(a) + " b=" + str(b) + " c=" + c)
print("")
# Python Numbers
print("Python Numbers")
a = 5
print(a, "is of type", type(a))
print("")
a = 2.0
print(a, "is of type", type(a))
print("")
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
print("")
# Python List (aka Array)
print("Python List")
a = [5,10,15,20,25,30,35,40]
# a[2] = 15
print("a[2] = ", a[2])
# a[0:3] = [5, 10, 15]
print("a[0:3] = ", a[0:3])
# a[5:] = [30, 35, 40]
print("a[5:] = ", a[5:])
print("")
# Python Tuple
print("Python Tuple")
import RPi.GPIO as GPIO
t = (5,"program", 1+3j)
# t[1] = "program"
print("t[1] = ", t[1])
# t[0:3] = (5, "program", (1+3j))
print("t[0:3] = ", t[0:3])
# Generates error
# Tuples are immutable
# t[0] = 10
print("")
# Python Strings
print("Python Strings")
s = "Hello world!"
# s[4] = "o"
print("s[4] = ", s[4])
# s[6:11] = "world"
print("s[6:11] = ", s[6:11])
# Generates error
# Strings are immutable in Python
# s[5] ="d"
print("")
# Python Set
print("Python Set")
a = {5,2,3,1,4}
# printing set variable
print("a = ", a)
# data type of variable a
print(type(a))
a = {1,2,2,3,3,3}
print("a = ", a)
print("")
# Python Dictionary
print("Python Dictionary")
d = {1:'value','key':2}
print(type(d))
print("d[1] = ", d[1]);
print("d['key'] = ", d['key']);
print("")