1. 程式人生 > 實用技巧 >字串雜湊 矩陣雜湊

字串雜湊 矩陣雜湊

技術標籤:基本知識python

# 面向物件-->class 類
# 面向過程-->def(無返回值,或返回null)
# 函數語言程式設計->def(有返回值return)

# 面向過程(定義功能或模組,程式中加以引用):
def func1():
    'test1說明體'
    print('it is func1..')

#面向物件:
def func2():
    'test2說明體'
    print('it is func2..')
    return 0

#二者都可以呼叫:

x = func1()
y = func2()

#程式執行結果 'it is func1..' 'it is func2..'
print('func1 返回值為 %s' %x) print('func2 返回值為 %s' %y) #程式執行結果為'func1 返回值為 none' 'func2 返回值為 0' #因此可以說:過程是無返回值或返回值為null的函式
with open('a.txt','a') as f:
    f.write('追加內容')

def func3():
    print('in the charpt3')
    with open('a.txt', 'a') as f:
        f.write('追加內容\n')

def func4():
    print('in the charpt4'
) with open('a.txt', 'a') as f: f.write('追加內容\n') def func5(): print('in the charpt5') with open('a.txt', 'a') as f: f.write('追加內容\n') func3() func4() func5() #a.txt 將換行輸出'追加內容’ #採用函式簡化程式碼如下 def logger(): with open('a.txt', 'a') as f: f.write('追加內容\n') def
func3(): print('in the charpt3') logger() def func4(): print('in the charpt4') logger() def func5(): print('in the charpt6') logger() func5() func4() func3()
#每個過程都想追加時間,只需要在第一個函式加入時間即可
import time

def logger():
    time_format = '%Y-%m-%d %X'
    time_current = time.strftime(time_format)
    with open('a.txt', 'a') as f:
        f.write('%s 追加內容\n' %time_current)

def func3():
    print('in the charpt3')
    logger()

def func4():
    print('in the charpt4')
    logger()

def func5():
    print('in the charpt6')
    logger()

func5()
func4()
func3()

#程式執行結果,a.txt內容為
在這裡插入圖片描述