编程小白的第一本 python 入门书 学习笔记03 第四章 函数



Python3.5有68个内建函数(Built-inFunction)

https://docs.python.org/3/library/functions.html

 

deffunctionName (arg1,arg2):

return 'someThing'

 

#华氏摄氏温度转换(有返回)

def fahrenheit_convert(C):
    fahrenheit=C*9/5+32
    return str(fahrenheit)+'F'

print(fahrenheit_convert(30))

 

 

#华氏摄氏温度转换(无返回)

def fahrenheit_converter(C):
    fahrenheit = C * 9/5 + 32
    print(str(fahrenheit) + '˚F')

 

fahrenheit_convert(30)

 

 

注意:批量注释和批量取消注释Ctrl+/

单行注释使用 #

多行注释使用 ''' '''(建议给描述使用) """ """

 

给函数传参

deftrapezoid_area(base_up, base_down, height):

   return 1/2 * (base_up + base_down) * height
 

trapezoid_area(1,2,3)

 

trapezoid_area(base_up=1,base_down=2, height=3)

 

trapezoid_area(height=3,base_down=2, base_up=1)   # RIGHT!

trapezoid_area(height=3,base_down=2, 1) # WRONG!

trapezoid_area(base_up=1,base_down=2, 3) # RIGHT!

trapezoid_area(1,2, height=3) # RIGHT!
 

def text_create(name, msg):
    #desktop_path = '/Users/Hou/Desktop/'

   desktop_path = r'C:\Users\HouDesktop\'
    full_path = desktop_path + name + '.txt'
    file = open(full_path,'w')
   file.write(msg)
   file.close()
    print('Done')

text_create('hello','hello world') #调用函数

 

 

a=10,b=20

a**b

a b 次方

a//b

取商的整数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值