本文实例讲述了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类的定义、继承及类对象使用方法简明教程
相关文章
相关视频
- 在Django框架中运行Python应用全攻略
- 在Python的Django框架中创建和使用模版
- python获取元素在数组中索引号的方法
- 浅谈python中截取字符函数strip,lstr...
- python简单的函数定义和用法实例
- Python 简介