日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonint()使用小結(jié)

Python int()使用小結(jié)

在下城等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需定制網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,成都全網(wǎng)營(yíng)銷推廣,外貿(mào)網(wǎng)站制作,下城網(wǎng)站建設(shè)費(fèi)用合理。

int()的基本語(yǔ)法格式是int(x,[base=10]),其中base可以省略

int()的作用是把不同進(jìn)制的數(shù)字或數(shù)字字符串轉(zhuǎn)為十進(jìn)制整數(shù)。使用中,其行為,參數(shù)有一些tricky,需要特別注意。

不帶參數(shù)返回0,即int()

>>> int()
0

取整是簡(jiǎn)單截?cái)?,不是四舍五?如int(1.5) = 1

>>> int(1.5)
1

參數(shù)可以是整數(shù),浮點(diǎn)數(shù),或算術(shù)表達(dá)式如100/3,但不能是復(fù)數(shù),如1+2j

>>> int(3)
3
>>> int(3.5)
3
>>> int(100/3)
33
>>> int(1+2j)
Traceback (most recent call last):
  File "", line 1, in 
    int(1+2j)
TypeError: can't convert complex to int

數(shù)字字符串可以是整數(shù)字符串如’123’,但不能是算術(shù)表達(dá)式字符串如’100/3’,或字符形式的浮點(diǎn)數(shù)如’1.5’

>>> int('123')
123
>>> int(100/3)
33
>>> int('100/3')
Traceback (most recent call last):
  File "", line 1, in 
    int('100/3')
ValueError: invalid literal for int() with base 10: '100/3'
>>> int('1.5')
Traceback (most recent call last):
  File "", line 1, in 
    int('1.5')
ValueError: invalid literal for int() with base 10: '1.5'

base缺省值是10,表示十進(jìn)制,如果包括base參數(shù),則前面的x必須是符合當(dāng)前進(jìn)制的數(shù)字字符串
此時(shí)int的作用是把base進(jìn)制代表的數(shù)字字符串x,轉(zhuǎn)換為10進(jìn)制數(shù)

>>> int('45',8)# 把8進(jìn)制'45'轉(zhuǎn)換為十進(jìn)制數(shù)37
37

>>> int('ab',16) #
171

>>> int(45,8)
Traceback (most recent call last):
  File "", line 1, in 
    int(45,8)
TypeError: int() can't convert non-string with explicit base
>>> int(ab,16)
Traceback (most recent call last):
  File "", line 1, in 
    int(ab,16)
NameError: name 'ab' is not defined

本文轉(zhuǎn)載自:https://blog.csdn.net/


分享文章:創(chuàng)新互聯(lián)Python教程:Pythonint()使用小結(jié)
URL地址:http://www.5511xx.com/article/dphohse.html