在本篇文章中小編給大家整理了關于int在python中的含義以及用法,對此有興趣的朋友們可以跟著學習下。
Python int() 函數文章源自四五設計網-http://www.wasochina.com/39182.html
描述文章源自四五設計網-http://www.wasochina.com/39182.html
int() 函數用于將一個字符串或數字轉換為整型。文章源自四五設計網-http://www.wasochina.com/39182.html
語法文章源自四五設計網-http://www.wasochina.com/39182.html
以下是 int() 方法的語法:文章源自四五設計網-http://www.wasochina.com/39182.html
1 | class int (x, base = 10 ) |
參數文章源自四五設計網-http://www.wasochina.com/39182.html
x -- 字符串或數字。
base -- 進制數,默認十進制。文章源自四五設計網-http://www.wasochina.com/39182.html
返回值文章源自四五設計網-http://www.wasochina.com/39182.html
返回整型數據。文章源自四五設計網-http://www.wasochina.com/39182.html
實例文章源自四五設計網-http://www.wasochina.com/39182.html
以下展示了使用 int() 方法的實例:
1 2 3 4 5 6 7 8 9 10 11 12 | >>> int ()??????? # 不傳入參數時,得到結果0 0 >>> int ( 3 ) 3 >>> int ( 3.6 ) 3 >>> int ( '12' , 16 )??? # 如果是帶參數base的話,12要以字符串的形式進行輸入,12 為 16進制 18 >>> int ( '0xa' , 16 ) 10 >>> int ( '10' , 8 ) 8 |
int在Python中有兩種意思:
一、表示Python的一種數字類型(有符號整型),
二、表示Python的一個內置函數int()函數,用于將一個字符串或數字轉換為整型。
語法:
1 | class int (x, base = 10 ) |
參數:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | x - - 字符串或數字。base - - 進制數,默認十進制。 返回值: 返回整型值。 >>> int ()??????? # 不傳入參數時,得到結果0 0 >>> int ( 3 ) 3 >>> int ( 3.6 ) 3 >>> int ( '12' , 16 )??? # 如果是帶參數base的話,12要以字符串的形式進行輸入,12 為 16進制 18 >>> int ( '0xa' , 16 ) 10 >>> int ( '10' , 8 ) 8 |
我的微信
微信掃一掃

我的微信
惠生活福利社
微信掃一掃

我的公眾號
評論