首页 > 编程语言 >Python-函数

Python-函数

时间:2023-02-08 16:13:11浏览次数:45  
标签:fahrenheit return 函数 area Python up down base

内建函数

help()

help(list.append)  #显示list的append方法的帮助

 

input()

name=input('please enter your name:') #读取输入,将读取到的数据赋值给指定变量

 

range() #生成一个列表

 

dir() #查看对象内所有属性及方法

 

type() #查看对象的数据类型

 

len() #字符串长度

 

定义函数

 

 

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

 

def trapezoid_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) #这种传参方式叫关键词参数

def trapezoid_area(base_up, base_down, height=3): #默认值参数
return 1/2 * (base_up + base_down) * height
trapezoid_area(1,2)

 


标签:fahrenheit,return,函数,area,Python,up,down,base
From: https://www.cnblogs.com/2023-1-6/p/17100928.html

相关文章