• 一个很小很小的体会


    关于python中的数学函数的体会:

    其实就是一个很小很小的学习心得。因为本身没有非常好好地学习其他编程语言,也没经验,就把自己学习的东西随时记录下来。

    当我用在循环中用min取最小值时,比用条件句去比较,效率更高。

    附上很简短的代码:

    import time
    2 import sys
    3 import os
    4 import skip_read
    5
    6 def Find_small(r):
    7
    8
    9     line=skip_read.process_file(r).strip()
    10 #   if line.startswith('-'):
    11 #       line=r.readline()
    12     print line
    13     value_smallest=int(line)
    14     for line in r:
    15         line=line.strip()
    16         print line
    17         if line!='-':
    18             value=int(line)
    19         else:
    20             continue
    21         value_smallest=min(value_smallest,value)                  if value<value_smallest: value_smallest=value
    22
    23     return value_smallest
    24
    25
    26 if __name__=="__main__":
    27
    28     in_file=file(sys.argv[1],'r')
    29     s=Find_small(in_file)
    30     print 'Among them,the smallest value is:'
    31     print s
    32     in_file.close()
    33     print time.clock()

    Result:

    $ python Find_smallest.py data.txt
    123
    35
    46
    687
    24
    14
    45
    456
    6
    Among them,the smallest value is:
    6
    0.078

    use min:

    $ python Find_smallest.py data.txt
    123
    35
    46
    687
    24
    14
    45
    456
    6
    Among them,the smallest value is:
    6
    0.046

  • 相关阅读:
    Linux
    Cookie & Session
    HTTP
    HTTP
    抓包工具
    抓包工具
    抓包工具
    python
    python
    python
  • 原文地址:https://www.cnblogs.com/hai-persist/p/3524034.html
Copyright © 2020-2023  润新知