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

yipeiwu_com6年前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调用cmd复制文件代码分享

复制代码 代码如下:import os def load() :    filename = os.getcwd() + r'\fromto.txt'&nb...

Pandas+Matplotlib 箱式图异常值分析示例

我就废话不多说了,直接上代码吧! # -*- coding: utf-8 -*- import pandas as pd import matplotlib.pyplot as...

python pdb调试方法分享

复制代码 代码如下:import pdbdef pdb_test(arg):    for i in range(arg):  &nbs...

Python语言描述机器学习之Logistic回归算法

Python语言描述机器学习之Logistic回归算法

本文介绍机器学习中的Logistic回归算法,我们使用这个算法来给数据进行分类。Logistic回归算法同样是需要通过样本空间学习的监督学习算法,并且适用于数值型和标称型数据,例如,我们...

Django JWT Token RestfulAPI用户认证详解

Django JWT Token RestfulAPI用户认证详解

一般情况下我们Django默认的用户系统是满足不了我们的需求的,那么我们会对他做一定的扩展 创建用户项目 python manage.py startapp users 添加项目a...