課程
/后端開(kāi)發(fā)
/Python
/Python3 進(jìn)階教程(新版)
sqrt(x)返回的是浮點(diǎn)數(shù)
2024-03-15
源自:Python3 進(jìn)階教程(新版) 8-5
正在回答
f(i).is_integer()
用is_integer()判斷返回的結(jié)果是不是整數(shù)。
sqrt 返回的是float類(lèi)型,用type int去判斷,可以無(wú)法返回值
import math
def f(n):
? ? r = int(math.sqrt(n))
? ? return r * r == n
print([item for item in filter(f, range(1, 101))])
舉報(bào)
學(xué)習(xí)函數(shù)式、模塊和面向?qū)ο缶幊?,掌握Python高級(jí)程序設(shè)計(jì)
3 回答count()返回的不是fs這個(gè)list嗎 為什么說(shuō)是返回函數(shù)呢?
5 回答我的運(yùn)行完都是1,請(qǐng)問(wèn)是哪里錯(cuò)了呀?
2 回答請(qǐng)問(wèn)這個(gè)哪里錯(cuò)了?
2 回答請(qǐng)問(wèn)下這個(gè)哪里錯(cuò)了?報(bào)錯(cuò)
1 回答localtion這個(gè)詞是想打location打錯(cuò)了,還是localtion有另外的意思呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2025-02-13
用is_integer()判斷返回的結(jié)果是不是整數(shù)。
2024-08-20
sqrt 返回的是float類(lèi)型,用type int去判斷,可以無(wú)法返回值
import math
def f(n):
? ? r = int(math.sqrt(n))
? ? return r * r == n
print([item for item in filter(f, range(1, 101))])