Python divmod 函数 - Python零基础入门教程
生活随笔
收集整理的這篇文章主要介紹了
Python divmod 函数 - Python零基础入门教程
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
- 一.divmod 函數(shù)介紹
- 二.divmod 函數(shù)使用
- 三.猜你喜歡
零基礎(chǔ) Python 學(xué)習(xí)路線推薦 :?Python 學(xué)習(xí)目錄?>>?Python 基礎(chǔ)入門
一.divmod 函數(shù)介紹
divmod 函數(shù)也是 Python 的內(nèi)置函數(shù),它是把除數(shù)和余數(shù)運算結(jié)果結(jié)合起來,返回一個包含商和余數(shù)的元組 tuple (a // b, a % b)
''' 參數(shù): x,y都是數(shù)字,可以是整形也可以是浮點數(shù),x 是分子,y 是分母;返回值:返回一個元組(x//y,x%y); ''' divmod(x,?y)二.divmod 函數(shù)使用
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python divmod函數(shù).py @Time:2021/04/04 11:00 @Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!"""print("{}".format(type(divmod(9,6)))) print("{}".format(divmod(9,6)))print("{}".format(type(divmod(9.2,6.6)))) print("{}".format(divmod(9.2,6.6)))''' 輸出結(jié)果:<class 'tuple'> (1, 3) <class 'tuple'> (1.0, 2.5999999999999996) '''注意:divmod 函數(shù)只能接受整數(shù) int 或浮點數(shù)類型 float 參數(shù),不能使用字符串 string , 否則會報錯!
三.猜你喜歡
未經(jīng)允許不得轉(zhuǎn)載:猿說編程 ? Python divmod 函數(shù)
總結(jié)
以上是生活随笔為你收集整理的Python divmod 函数 - Python零基础入门教程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python 局部变量和全局变量 - P
- 下一篇: Python变量 - Python零基础