python简单的函数定义和用法实例

python教程评论1.2K views阅读模式

本文实例讲述了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 函数定义 用法
  • 本文原创发布php教程 ,转载请注明出处,感谢您的尊重!
    • 上一篇:python自定义类并使用的方法
    • 下一篇:Python类的定义、继承及类对象使用方法简明教程

    相关文章

    相关视频

    • 在Django框架中运行Python应用全攻略
    • 在Python的Django框架中创建和使用模版
    • python获取元素在数组中索引号的方法
    • 浅谈python中截取字符函数strip,lstr...
    • python简单的函数定义和用法实例
    • Python 简介

    企鹅博客
    • 本文由 发表于 2019年8月11日 13:15:48
    • 转载请务必保留本文链接:https://www.qieseo.com/335592.html

    发表评论