-
Notifications
You must be signed in to change notification settings - Fork 1
/
python_basics.py
141 lines (112 loc) · 1.81 KB
/
python_basics.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# printing
print("Hello world")
print(2 + 3)
print("2" * 6)
#variables
x = 5
y = 'Hi how\'s it going?'
print(x, " ", y)
print( type(y) )
#type function
y = 10
print(y)
print( type(y) )
#multiple assignment
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
#strings
word = "excellant"
print(len(word))
print(word[2:])
#operators and conditionals
print(10 > 9)
print(10 == 9)
print(10 < 9)
#lists
thislist = ["apple", "banana", "cherry"]
print(thislist)
print(len(thislist))
list1 = ["abc", 34, True, 40, "male"]
print(list1[0])
print(list1[1])
list1.append("New Item")
print(list1)
list1.remove("abc")
print(list1)
list1.pop(2)
print(list1)
#tuple
thistuple = ("apple", "banana", "cherry", "apple", "cherry")
print(thistuple)
a = 33
b = 200
if b > a:
print("b is greater than a")
#if-else
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
if a > b: print("a is greater than b")
#and & or
a = 200
b = 33
c = 500
if a > b and c > a:
print("Both conditions are True")
a = 200
b = 33
c = 500
if a > b or a > c:
print("At least one of the conditions is True")
#loops
i = 1
while i < 6:
print(i)
i += 1
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)
i = 1
while i < 6:
print(i)
i += 1
else:
print("i is no longer less than 6")
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
for x in range(2, 6):
print(x)
for x in [0, 1, 2]:
pass
#functions
def add(x, y):
return x + y
def is_even(num):
if num % 2 == 0:
return True
return False
def print_email(email = "[email protected]"):
print(email)