自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python函數(shù)中三大主要應(yīng)用形式

開發(fā) 后端
Python函數(shù)是Python編程語言中的精髓,有不少的知識需要我們學(xué)習(xí),下面我們就來看看在Python函數(shù)中最重要的三大函數(shù)應(yīng)用。

Python函數(shù)在使用的時候有幾大分類,其中以int函數(shù),float函數(shù)和str函數(shù)的應(yīng)用最為廣泛。下面我們就看看具體的環(huán)境中如何進行相關(guān)的函數(shù)代碼的編寫。下面我們先來看看int函數(shù)在Python函數(shù)中的作用。

(1)把符合數(shù)學(xué)格式的數(shù)字型字符串轉(zhuǎn)換成整數(shù)

(2)把浮點數(shù)轉(zhuǎn)換成整數(shù),但是只是簡單的取整,而非四舍五入。

舉例:

  1. aa = int("124") #Correct   
  2. print "aa = ", aa #result=124   
  3. bb = int(123.45) #correct   
  4. print "bb = ", bb #result=123   
  5. cc = int("-123.45") #Error,Can't Convert to int   
  6. print "cc = ",cc   
  7. dd = int("34a") #Error,Can't Convert to int   
  8. print "dd = ",dd   
  9. ee = int("12.3") #Error,Can't Convert to int  
  10. print ee 

float函數(shù)將整數(shù)和字符串轉(zhuǎn)換成浮點數(shù)。

舉例:

  1. aa = float("124") #Correct   
  2. print "aa = ", aa #result = 124.0   
  3. bb = float("123.45") #Correct   
  4. print "bb = ", bb #result = 123.45   
  5. cc = float(-123.6) #Correct   
  6. print "cc = ",cc #result = -123.6   
  7. dd = float("-123.34") #Correct   
  8. print "dd = ",dd #result = -123.34   
  9. ee = float('123v') #Error,Can't Convert to float  
  10. print ee  

Python str函數(shù)將數(shù)字轉(zhuǎn)換成字符舉例:

  1. aa = str(123.4) #Correct   
  2. print aa #result = '123.4'   
  3. bb = str(-124.a) #SyntaxError: invalid syntax   
  4. print bb   
  5. cc = str("-123.45") #correct   
  6. print cc #result = '-123.45'   
  7. dd = str('ddd') #correct   
  8. print dd #result = ddd   
  9. ee = str(-124.3) #correct  
  10. print ee #result = -124.3 

以上就是對Python函數(shù)的三大類進行的分析,希望大家有所收獲。

【編輯推薦】

  1. 使用Python函數(shù)編譯函數(shù)
  2. 如何定義Python函數(shù)說明
  3. 深度剖析Python函數(shù)編程技巧
  4. 如何正確的使用Python函數(shù)
  5. C調(diào)用Python函數(shù)相關(guān)代碼示例剖析
責(zé)任編輯:張浩 來源: TT網(wǎng)絡(luò)
相關(guān)推薦

2010-03-24 10:32:05

Python多線程

2010-04-19 09:31:44

KDE

2010-07-23 13:07:39

Perl

2010-09-15 13:50:04

CSSposition屬性

2010-10-08 09:26:45

JavaScript程

2010-03-10 15:19:06

Python源代碼

2010-03-24 10:32:05

Python多線程

2010-09-28 09:49:49

DOM模型

2010-08-16 11:33:16

DIV定位

2010-08-13 13:39:51

Flex效果組件

2010-09-30 16:06:21

J2ME平臺

2011-08-01 09:51:20

云計算

2010-03-11 15:01:52

Python源碼

2024-11-14 11:00:00

Python繼承機制

2024-04-11 12:57:55

Python函數(shù)

2021-07-10 10:01:37

Python簡單函數(shù)

2021-03-17 09:59:26

Python函數(shù)調(diào)用

2009-09-15 10:46:06

Visual Stud

2021-08-23 16:07:29

人工智能智慧城市安防

2010-03-11 19:45:09

Python邏輯
點贊
收藏

51CTO技術(shù)棧公眾號