Skip to content

Commit 3d760af

Browse files
committed
Added the lesson 2 module
1 parent 5ae7fb4 commit 3d760af

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

lesson1/hello_world.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
print("\t\tii. from module import name")
1111
print("\t\tiii. from module import name as shortName")
1212
print('v. To know the methods use python help method as below ')
13-
print("\t\t>>> help() or help(math)")
14-
print('vi. To use any library function import library.')
13+
print("\t\t>>> help() or help(math)") # help(library name)
14+
print('vi. Generally, four whitespaces are used for indentation and are preferred over tabs.')
15+
print('vii. To use any library function import library.')
1516
print("\tEX:")
1617
print("\t\ti. import math")
1718
print("\t\tii. from math import factorial")
1819
print("\t\tiii. from math import factorial as fac")
1920
print("\nNext check factorial program to know more about importing library >> ".upper())
20-
21-
21+
"""
22+
I am a
23+
multi line
24+
comment
25+
"""
26+
# prefer # over 3". because if we assign it to any variable it will take that value.
27+
# I am also
28+
# a multi line
29+
# comments

lesson2/ScalarTypes.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
print("Scalar data types: \n\tintegers, \n\tfloats, \n\tNone (str) and \n\tbool")
2+
3+
# Assigning multiple values to multiple variables
4+
a, b, c = 5, 3.2, "Hello"
5+
6+
print(a)
7+
print(b)
8+
print(c)
9+
10+
# assign the same value to multiple variables at once
11+
x = y = z = "same"
12+
13+
print(x)
14+
print(y)
15+
print(z)
16+
17+
# To write multiple statements in the line use ;
18+
z = "not same"; print(y); print(z)
19+
20+
# int type
21+
a = 0b1010 # Binary Literals
22+
b = 100 # Decimal Literal
23+
c = 0o310 # Octal Literal
24+
d = 0x12c # Hexadecimal Literal
25+
26+
# float type
27+
float_1 = 10.5
28+
float_2 = 1.5e2
29+
30+
# Complex Literal
31+
x = 3.14j
32+
33+
# Constant should be full uppercase But we can change the value here.
34+
PI = 13.14
35+
PI = PI - 10
36+
37+
# str type
38+
strings = "This is Python"
39+
char = "C"
40+
string1 = None # similar to null in java which is nothing
41+
42+
# use , to concatenate the strings. similar + in java
43+
print(a, b, c, d)
44+
print(float_1, float_2)
45+
print(x, x.imag, x.real)
46+
print(PI)
47+
print(strings, char, string1)
48+
49+
# bool type True or False
50+
x = (1 == True)
51+
y = (1 == False)
52+
a = True + 4 # True is 1
53+
b = False + 10 # False is 0
54+
55+
print("x is", x)
56+
print("y is", y)
57+
print("a:", a)
58+
print("b:", b)
59+
print("all the below stmt return False")
60+
print(bool(0)) # False
61+
print(bool(0.0)) # False
62+
print(bool("")) # False ? empty string
63+
print(bool({})) # False ? empty dict
64+
print(bool([])) # False ? empty list
65+
print(bool(())) # False ? empty tuple
66+
67+
print("all the below stmt return True")
68+
# Rest is True
69+
print(bool("True")) # True
70+
print(bool("False")) # True
71+
print(bool("0")) # True
72+
print(bool(0.01)) # True
73+
print(bool(-12)) # True
74+
print(bool(2)) # True
75+
76+
fruits = ["apple", "mango", "orange"] # list
77+
numbers = (1, 2, 3) # tuple
78+
alphabets = {'a': 'apple', 'b': 'ball', 'c': 'cat'} # dictionary
79+
vowels = {'a', 'e', 'i', 'o', 'u'} # set
80+
81+
print(fruits, " is a ", type(fruits))
82+
print(numbers, " is a ", type(numbers))
83+
print(alphabets, " is a ", type(alphabets))
84+
print(vowels, " is a ", type(vowels))
85+
86+
# type is used to find the type of variable or class name.
87+
print(type(1))
88+
print(type(1.2))
89+
print(type("me"))
90+
print(type(False))

lesson2/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)