Python divmod 函数 - Python零基础入门教程
生活随笔
收集整理的這篇文章主要介紹了
Python divmod 函数 - Python零基础入门教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 一.divmod 函數介紹
- 二.divmod 函數使用
- 三.猜你喜歡
零基礎 Python 學習路線推薦 :?Python 學習目錄?>>?Python 基礎入門
一.divmod 函數介紹
divmod 函數也是 Python 的內置函數,它是把除數和余數運算結果結合起來,返回一個包含商和余數的元組 tuple (a // b, a % b)
''' 參數: x,y都是數字,可以是整形也可以是浮點數,x 是分子,y 是分母;返回值:返回一個元組(x//y,x%y); ''' divmod(x,?y)二.divmod 函數使用
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python divmod函數.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)))''' 輸出結果:<class 'tuple'> (1, 3) <class 'tuple'> (1.0, 2.5999999999999996) '''注意:divmod 函數只能接受整數 int 或浮點數類型 float 參數,不能使用字符串 string , 否則會報錯!
三.猜你喜歡
未經允許不得轉載:猿說編程 ? Python divmod 函數
總結
以上是生活随笔為你收集整理的Python divmod 函数 - Python零基础入门教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python 局部变量和全局变量 - P
- 下一篇: BugkuCTF-MISC题隐写