函数01(功能,命名规则)

作用:
1.避免重复性操作
2.方便修改,更易扩展
3.保持代码一致性
4,容易读懂
2.2函数命令规则
(1)函数名必须以字母或下划线开头,可以包含任意字母/数字或下划线的组合。不能使用任何的标点符号
(2)函数名是区分大小写的
(3)函数名不能是保留字
2.3形参和实参
#举例
print("---function 1")
# f = open("2018-0914 11:15 log.txt",'a')
# f.write("exec function 2")
# f.close()
#function
# def func():
# print('scott')
# #func() #加括号调用函数
#
# def add(x,y): #形参 按顺序对应 形参、实参个数一样
# print(x+y)
# print(x)
# print(y)
# add(2,3) #实参
#
# def a(b,a): #
# print(a)
# print(b)
# a(7,9)
# def f(a):
# print('function %s'% (a) )
# f(3)
import time
#time_format = '%Y-%m-%d %X'
#time_current = time.strftime(time_format)
#print(time_current)
def logger(n):
time_format = '%Y-%m-%d %X'
time_current = time.strftime( time_format )
with open('日质记录','a') as f:
f.write('%s end action%s\n'%(time_current,n))

def action1(n):
print('starting action 1...')
logger(n)
def action2(n):
print( 'starting action 2...' )
logger(n)
def action3(n):
print('starting action 3...')
logger(n)
action1(11)
action2(22)
action3(33)

猜你喜欢

转载自www.cnblogs.com/scottsofia/p/10106736.html