Skip to content

Commit e32fc5c

Browse files
authored
Examples in Python for 1st, 2nd and 3rd files (HowProgrammingWorks#12)
1 parent 218110c commit e32fc5c

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

Python/1-comments.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# single comment
2+
3+
4+
"""
5+
Multiline comments do not actualy exist in Python
6+
Sometimes you can meet creating of multiline comments by using tripple quotes,
7+
but that is not a comments in general.
8+
Tripple quotes in python treats as regular string and
9+
if it is not assigned to any variable it will be immediately garbage collected
10+
as soon as that code executes. So it doesn't affect execution.
11+
"""

Python/2-declaration.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#print(a)
2+
#NameError: name 'a' is not defined
3+
4+
a = 5
5+
print(a)
6+
type(a)
7+
#<class 'int'>
8+
9+
b = 5.2
10+
11+
dic = {'d': a, 'c': b}
12+
#obj
13+
print("Dictionary is: ", dic)
14+
15+
dic['c'] = 10
16+
print("Dictionary has been changed: ", dic)

Python/3-types.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
a = 5
2+
print(type(a))
3+
4+
b = 5.2
5+
print(type(b))
6+
#<class 'float'>
7+
8+
print(type(True))
9+
#<class 'bool'>
10+
11+
print(type(2+3j))
12+
#<class 'complex'>
13+
14+
print(type('hello'))
15+
#<class 'str'>
16+
17+
18+
person = {
19+
'name': 'Rikardo',
20+
'age': 27,
21+
'profession': 'actor'
22+
}
23+
24+
person['age'] = 28
25+
print(person)
26+
27+
array = {a, b, '56'}
28+
print('Arrray ', array)
29+
print(type(array))

0 commit comments

Comments
 (0)