1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

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

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      python3函數(shù)幫助 python函數(shù)功能

      python3--內(nèi)置函數(shù)

      python的常用內(nèi)置函數(shù)

      成都創(chuàng)新互聯(lián)公司專注于鹽田網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供鹽田營銷型網(wǎng)站建設(shè),鹽田網(wǎng)站制作、鹽田網(wǎng)頁設(shè)計(jì)、鹽田網(wǎng)站官網(wǎng)定制、成都小程序開發(fā)服務(wù),打造鹽田網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供鹽田網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

      1.abs() 函數(shù)返回?cái)?shù)字的絕對(duì)值

      abs(-40)=40

      2. dict() 函數(shù)用于創(chuàng)建一個(gè)字典

      dict()

      {} ? ? ?#創(chuàng)建一個(gè)空字典類似于u={},字典的存取方式一般為key-value

      例如u = {"username":"tom", ?"age":18}

      3. help() 函數(shù)用于查看函數(shù)或模塊用途的詳細(xì)說明

      help('math')查看math模塊的用處

      a=[1,2,3,4]

      help(a)查看列表list幫助信息

      4.dir()獲得當(dāng)前模塊的屬性列表

      dir(help)

      ['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']

      5.min() 方法返回給定參數(shù)的最小值 /參數(shù)可以為序列

      a=? min(10,20,30,40)

      a

      10

      6. next() 返回迭代器的下一個(gè)項(xiàng)目

      it = iter([1, 2, 3, 4, 5])

      next(it)

      1

      next(it)

      2

      7. id() 函數(shù)用于獲取對(duì)象的內(nèi)存地址

      a=12

      id(a)

      1550569552

      8.enumerate() 函數(shù)用于將一個(gè)可遍歷的數(shù)據(jù)對(duì)象(如列表、元組或字符串)組合為一個(gè)索引序列,同時(shí)列出數(shù)據(jù)和數(shù)據(jù)下標(biāo),一般用在 for 循環(huán)當(dāng)中。

      a=["tom","marry","leblan"]

      list(enumerate(a))

      [(0, 'tom'), (1, 'marry'), (2, 'leblan')]

      9. oct() 函數(shù)將一個(gè)整數(shù)轉(zhuǎn)換成8進(jìn)制字符串

      oct(15)

      '0o17'

      oct(10)

      '0o12'

      10. bin() 返回一個(gè)整數(shù) int 或者長整數(shù) long int 的二進(jìn)制表示

      bin(10)

      '0b1010'

      bin(15)

      '0b1111'

      11.eval() 函數(shù)用來執(zhí)行一個(gè)字符串表達(dá)式,并返回表達(dá)式的值

      eval('2+2')

      4

      12.int() 函數(shù)用于將一個(gè)字符串會(huì)數(shù)字轉(zhuǎn)換為整型

      int(3)

      3

      int(3.6)

      3

      int(3.9)

      3

      int(4.0)

      4

      13.open() 函數(shù)用于打開一個(gè)文件,創(chuàng)建一個(gè)file對(duì)象,相關(guān)的方法才可以調(diào)用它進(jìn)行讀寫

      f=open('test.txt')

      14.str() 函數(shù)將對(duì)象轉(zhuǎn)化為適于人閱讀的形式

      str(3)

      '3'

      15. bool() 函數(shù)用于將給定參數(shù)轉(zhuǎn)換為布爾類型,如果沒有參數(shù),返回 False

      bool()

      False

      bool(1)

      True

      bool(10)

      True

      bool(10.0)

      True

      16.isinstance() 函數(shù)來判斷一個(gè)對(duì)象是否是一個(gè)已知的類型

      a=5

      isinstance(a,int)

      True

      isinstance(a,str)

      False

      17. sum() 方法對(duì)系列進(jìn)行求和計(jì)算

      sum([1,2,3],5)

      11

      sum([1,2,3])

      6

      18. super() 函數(shù)用于調(diào)用下一個(gè)父類(超類)并返回該父類實(shí)例的方法。super 是用來解決多重繼承問題的,直接用類名調(diào)用父類方法

      class ? User(object):

      ? def__init__(self):

      class Persons(User):

      ? ? ? ? super(Persons,self).__init__()

      19. float() 函數(shù)用于將整數(shù)和字符串轉(zhuǎn)換成浮點(diǎn)數(shù)

      float(1)

      1.0

      float(10)

      10.0

      20. iter() 函數(shù)用來生成迭代器

      a=[1,2,3,4,5,6]

      iter(a)

      for i in iter(a):

      ... ? ? ? ? print(i)

      ...

      1

      2

      3

      4

      5

      6

      21.tuple 函數(shù)將列表轉(zhuǎn)換為元組

      a=[1,2,3,4,5,6]

      tuple(a)

      (1, 2, 3, 4, 5, 6)

      22.len() 方法返回對(duì)象(字符、列表、元組等)長度或項(xiàng)目個(gè)數(shù)

      s = "playbasketball"

      len(s)

      14

      a=[1,2,3,4,5,6]

      len(a)

      6

      23. property() 函數(shù)的作用是在新式類中返回屬性值

      class User(object):

      ?def __init__(self,name):

      ? ? ? ? ? self.name = name

      def get_name(self):

      ? ? ? ? ? return self.get_name

      @property

      ?def name(self):

      ? ? ? ? ?return self_name

      24.type() 函數(shù)返回對(duì)象的類型

      25.list() 方法用于將元組轉(zhuǎn)換為列表

      b=(1,2,3,4,5,6)

      list(b)

      [1, 2, 3, 4, 5, 6]

      26.range() 函數(shù)可創(chuàng)建一個(gè)整數(shù)列表,一般用在 for 循環(huán)中

      range(10)

      range(0, 10)

      range(10,20)

      range(10, 20)

      27. getattr() 函數(shù)用于返回一個(gè)對(duì)象屬性值

      class w(object):

      ... ? ? ? ? ? ? s=5

      ...

      a = w()

      getattr(a,'s')

      5

      28. complex() 函數(shù)用于創(chuàng)建一個(gè)復(fù)數(shù)或者轉(zhuǎn)化一個(gè)字符串或數(shù)為復(fù)數(shù)。如果第一個(gè)參數(shù)為字符串,則不需要指定第二個(gè)參數(shù)

      complex(1,2)

      (1+2j)

      complex(1)

      (1+0j)

      complex("1")

      (1+0j)

      29.max() 方法返回給定參數(shù)的最大值,參數(shù)可以為序列

      b=(1,2,3,4,5,6)

      max(b)

      6

      30. round() 方法返回浮點(diǎn)數(shù)x的四舍五入值

      round(10.56)

      11

      round(10.45)

      10

      round(10.45,1)

      10.4

      round(10.56,1)

      10.6

      round(10.565,2)

      10.56

      31. delattr 函數(shù)用于刪除屬性

      class Num(object):

      ...? ? a=1

      ...? ? b=2

      ...? ? c=3.

      .. print1 = Num()

      print('a=',print1.a)

      a= 1

      print('b=',print1.b)

      b= 2

      print('c=',print1.c)

      c= 3

      delattr(Num,'b')

      print('b=',print1.b)

      Traceback (most recent call last):? File "", line 1, inAttributeError: 'Num' object has no attribute 'b'

      32. hash() 用于獲取取一個(gè)對(duì)象(字符串或者數(shù)值等)的哈希值

      hash(2)

      2

      hash("tom")

      -1675102375494872622

      33. set() 函數(shù)創(chuàng)建一個(gè)無序不重復(fù)元素集,可進(jìn)行關(guān)系測試,刪除重復(fù)數(shù)據(jù),還可以計(jì)算交集、差集、并集等。

      a= set("tom")

      b = set("marrt")

      a,b

      ({'t', 'm', 'o'}, {'m', 't', 'a', 'r'})

      ab#交集

      {'t', 'm'}

      a|b#并集

      {'t', 'm', 'r', 'o', 'a'}

      a-b#差集

      {'o'}

      太全了!Python3常用內(nèi)置函數(shù)總結(jié)

      數(shù)學(xué)相關(guān)

      abs(a) : 求取絕對(duì)值。abs(-1)

      max(list) : 求取list最大值。max([1,2,3])

      min(list) : 求取list最小值。min([1,2,3])

      sum(list) : 求取list元素的和。 sum([1,2,3]) 6

      sorted(list) : 排序,返回排序后的list。

      len(list) : list長度,len([1,2,3])

      divmod(a,b): 獲取商和余數(shù)。 divmod(5,2) (2,1)

      pow(a,b) : 獲取乘方數(shù)。pow(2,3) 8

      round(a,b) : 獲取指定位數(shù)的小數(shù)。a代表浮點(diǎn)數(shù),b代表要保留的位數(shù)。round(3.1415926,2) 3.14

      range(a[,b]) : 生成一個(gè)a到b的數(shù)組,左閉右開。range(1,10) [1,2,3,4,5,6,7,8,9]

      類型轉(zhuǎn)換

      int(str) : 轉(zhuǎn)換為int型。int('1') 1

      float(int/str) : 將int型或字符型轉(zhuǎn)換為浮點(diǎn)型。float('1') 1.0

      str(int) : 轉(zhuǎn)換為字符型。str(1) '1'

      bool(int) : 轉(zhuǎn)換為布爾類型。 str(0) False str(None) False

      bytes(str,code) : 接收一個(gè)字符串,與所要編碼的格式,返回一個(gè)字節(jié)流類型。bytes('abc', 'utf-8') b'abc' bytes(u'爬蟲', 'utf-8') b'xe7x88xacxe8x99xab'

      list(iterable) : 轉(zhuǎn)換為list。 list((1,2,3)) [1,2,3]

      iter(iterable): 返回一個(gè)可迭代的對(duì)象。 iter([1,2,3]) list_iterator object at 0x0000000003813B00

      dict(iterable) : 轉(zhuǎn)換為dict。 dict([('a', 1), ('b', 2), ('c', 3)]) {'a':1, 'b':2, 'c':3}

      enumerate(iterable) : 返回一個(gè)枚舉對(duì)象。

      tuple(iterable) : 轉(zhuǎn)換為tuple。 tuple([1,2,3]) (1,2,3)

      set(iterable) : 轉(zhuǎn)換為set。 set([1,4,2,4,3,5]) {1,2,3,4,5} set({1:'a',2:'b',3:'c'}) {1,2,3}

      hex(int) : 轉(zhuǎn)換為16進(jìn)制。hex(1024) '0x400'

      oct(int) : 轉(zhuǎn)換為8進(jìn)制。 oct(1024) '0o2000'

      bin(int) : 轉(zhuǎn)換為2進(jìn)制。 bin(1024) '0b10000000000'

      chr(int) : 轉(zhuǎn)換數(shù)字為相應(yīng)ASCI碼字符。 chr(65) 'A'

      ord(str) : 轉(zhuǎn)換ASCI字符為相應(yīng)的數(shù)字。 ord('A') 65

      相關(guān)操作

      eval****() : 執(zhí)行一個(gè)表達(dá)式,或字符串作為運(yùn)算。 eval('1+1') 2

      exec() : 執(zhí)行python語句。 exec('print("Python")') Python

      filter(func, iterable) : 通過判斷函數(shù)fun,篩選符合條件的元素。 filter(lambda x: x3, [1,2,3,4,5,6]) filter object at 0x0000000003813828

      map(func, *iterable) : 將func用于每個(gè)iterable對(duì)象。 map(lambda a,b: a+b, [1,2,3,4], [5,6,7]) [6,8,10]

      zip(*iterable) : 將iterable分組合并。返回一個(gè)zip對(duì)象。 list(zip([1,2,3],[4,5,6])) [(1, 4), (2, 5), (3, 6)]

      type():返回一個(gè)對(duì)象的類型。

      id(): 返回一個(gè)對(duì)象的唯一標(biāo)識(shí)值。

      hash(object):返回一個(gè)對(duì)象的hash值,具有相同值的object具有相同的hash值。 hash('python') 7070808359261009780

      help():調(diào)用系統(tǒng)內(nèi)置的幫助系統(tǒng)。

      isinstance():判斷一個(gè)對(duì)象是否為該類的一個(gè)實(shí)例。

      issubclass():判斷一個(gè)類是否為另一個(gè)類的子類。

      globals() : 返回當(dāng)前全局變量的字典。

      next(iterator[, default]) : 接收一個(gè)迭代器,返回迭代器中的數(shù)值,如果設(shè)置了default,則當(dāng)?shù)髦械脑乇闅v后,輸出default內(nèi)容。

      reversed(sequence) : 生成一個(gè)反轉(zhuǎn)序列的迭代器。 reversed('abc') ['c','b','a']

      Python怎么查看幫助信息

      Python獲取幫助的3種方式

      help()

      help函數(shù)是Python的一個(gè)內(nèi)置函數(shù)。

      函數(shù)原型:help([object])。

      可以幫助我們了解該對(duì)象的更多信息。

      dir()

      dir函數(shù)是Python的一個(gè)內(nèi)置函數(shù)。

      函數(shù)原型:dir([object])

      可以幫助我們獲取該對(duì)象的大部分相關(guān)屬性。

      _?doc_

      在Python中有一個(gè)奇妙的特性,文檔字符串,又稱為DocStrings。

      用它可以為我們的模塊、類、函數(shù)等添加說明性的文字,使程序易讀易懂,更重要的是可以通過Python自帶的標(biāo)準(zhǔn)方法將這些描述性文字信息輸出。

      上面提到的自帶的標(biāo)準(zhǔn)方法就是_?doc?_。前后各兩個(gè)下劃線。

      注:當(dāng)不是函數(shù)、方法、模塊等調(diào)用doc時(shí),而是具體對(duì)象調(diào)用時(shí),會(huì)顯示此對(duì)象從屬的類型的構(gòu)造函數(shù)的文檔字符串。


      當(dāng)前標(biāo)題:python3函數(shù)幫助 python函數(shù)功能
      文章源于:http://ef60e0e.cn/article/dospsdj.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        曲松县| 苍梧县| 克拉玛依市| 门头沟区| 嘉荫县| 太白县| 五大连池市| 浮梁县| 交口县| 白朗县| 阿城市| 富宁县| 和顺县| 平谷区| 同江市| 元阳县| 汕尾市| 滕州市| 鹿泉市| 谢通门县| 上思县| 盈江县| 视频| 双鸭山市| 吴江市| 社旗县| 都昌县| 梨树县| 女性| 兴文县| 晴隆县| 仁布县| 景泰县| 大理市| 鞍山市| 岳池县| 临沧市| 莒南县| 佳木斯市| 元谋县| 玉龙|