python简单的函数定义和用法实例
2015-05-07 00:00
781 查看
本文实例讲述了python简单的函数定义和用法。分享给大家供大家参考。具体分析如下:
这里定义了一个温度转换的函数及其用法。
希望本文所述对大家的Python程序设计有所帮助。
这里定义了一个温度转换的函数及其用法。
def convertTemp(temp, scale): if scale == "c": return (temp - 32.0) * (5.0/9.0) elif scale == "f": return temp * 9.0/5.0 + 32 temp = int(input("Enter a temperature: ")) scale = input("Enter the scale to convert to: ") converted = convertTemp(temp, scale) print("The converted temp is: " + str(converted))
希望本文所述对大家的Python程序设计有所帮助。
相关文章推荐
- python简单的函数定义和用法实例
- Python生成器定义与简单用法实例分析
- Python中函数的参数定义和可变参数用法实例分析
- python正则表达式--基本用法和函数(简单实例)
- Python中函数的参数定义和可变参数用法实例分析
- Python可变参数函数用法实例
- Python函数可变参数定义及其参数传递方式实例详解
- Python中property函数用法实例分析
- python简单定义函数
- python函数局部变量用法实例分析
- python3中函数参数的四种简单用法
- Python中dictionary items()系列函数的用法实例
- Python函数中的函数(闭包)用法实例
- python中while循环语句用法简单实例
- python中操作文件函数open的简单操作实例
- $聊一聊"驼峰"和"下划线"——Python re.sub函数详细用法实例讲解
- Python3.2中Print函数用法实例详解
- Python中函数的用法实例教程
- Python中函数定义及参数实例
- Python工厂函数用法实例分析