-
Notifications
You must be signed in to change notification settings - Fork 3
/
hello.py
58 lines (39 loc) · 1.52 KB
/
hello.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
# How to run this program:
# In terminal, run $python3 hello.py
import functools, os
import datetime
print("Hello world!")
txt = "Viel Glück!"
print("Before encoding, txt: ", txt)
print("After encoding with UTF-8, x: ", txt.encode()) # without specifiying encoding scheme, UTF-8 is used
print("After encoding with ascii, x: ", txt.encode(encoding="ascii",errors="namereplace"))
# for _ in range(10):
# print("Hello world!")
s = 'django'
print(s[0])
print(s[-1])
print(s[:4])
print(s[1:4])
print(s[4:])
var = {'k1':[{'nest_key':['this is deep',['hello']]}]}
# [] means a list, {} means a dict,
# so there is list inside the dict and inside list and inside dict. ^ ^
print("printing out var from nested dict: ", var['k1'][0]['nest_key'][1])
print("Program finished!")
def add(a, b):
return a * b
print(functools.reduce(add, [1, 2, 3]))
print(__file__) # this prints out the absolute path of this current file on this machine.
print(os.path.abspath(__file__))
def main():
print("Hello World!")
file_content = "72324970,abc,def\n72324990,ghi,123\n"
lines = file_content.splitlines()
for i, line in enumerate(lines):
print('line[{}] = {}'.format(i, line))
# below three lines show the difference of a timestamp and a human readable date and how to get them in Python
now = datetime.datetime.now()
print("now.strftime(\"%Y-%m-%d %H:%M:%S\") is: {}".format(now.strftime("%Y-%m-%d %H:%M:%S")))
print("now.timestamp() is: {}".format(int(now.timestamp())))
if __name__ == "__main__":
main()