Skip to content

Commit 767fa36

Browse files
committed
Adds assign, comment, conditional & function eg
1 parent d8504fc commit 767fa36

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

codes/ch1_syntax/assignment.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/python3
2+
3+
def main():
4+
a = 1
5+
b = "Ashwin"
6+
print("a = {}, b = {}".format(a, b))
7+
print("Type of a is: {}".format(type(a)))
8+
print("Type of b is: {}".format(type(b)))
9+
10+
c = (1, 2, 3, 4, 5)
11+
print(c)
12+
13+
d = [1, 2, 3, 4, 5]
14+
print(d)
15+
16+
if __name__ == "__main__": main()
File renamed without changes.

codes/ch1_syntax/conditional.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python3
2+
3+
def main():
4+
a, b = 5, 10
5+
if a < b:
6+
print("a({}) is less than b({})".format(a, b))
7+
else:
8+
print("a({}) is not less than b({})".format(a, b))
9+
10+
if __name__ == "__main__": main()

codes/ch1_syntax/function.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/python3
2+
3+
# def is used to define a function
4+
# Syntax:
5+
# def <function-name>(<param1>, <param2>, ...):
6+
def main():
7+
print("Main function")
8+
addition(45, 45)
9+
addition()
10+
11+
# a and b are having default values
12+
def addition(a = 5, b = 5):
13+
print("Addition: ", a + b)
14+
15+
16+
if __name__ == "__main__": main()

0 commit comments

Comments
 (0)