zoukankan      html  css  js  c++  java
  • f开头的

    '''
    fabs() 方法返回数字的绝对值,如math.fabs(-10) 返回10.0。
    fabs() 函数类似于 abs() 函数,但是他有两点区别:
    abs() 是内置函数。 fabs() 函数在 math 模块中定义。
    fabs() 函数只对浮点型跟整型数值有效。 abs() 还可以运用在复数中
    import math
    math.fabs( x )
    注意:fabs()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。
    x -- 数值表达式。
    返回数字的绝对值。
    '''
    import math # 导入 math 模块
    print ("math.fabs(-11.17) : ", math.fabs(-11.17))
    print ("math.fabs(10.12) : ", math.fabs(10.12))
    print ("math.fabs(10.72) : ", math.fabs(10.72))
    print ("math.fabs(math.pi) : ", math.fabs(math.pi)) # 3.141592653589793
    print('-'*10,"分割线","-"*10)
    
    '''
    filter() 函数用于过滤序列,过滤掉不符合条件的元素,返回一个迭代器对象,
    如果要转换为列表,可以使用 list() 来转换。
    该接收两个参数,第一个为函数,第二个为序列,序列的每个元素作为参数传递给函数进行判别,
    然后返回 True 或 False,最后将返回 True 的元素放到新列表中。
    filter(function, iterable)
    function -- 判断函数。
    iterable -- 可迭代对象。
    返回一个迭代器对象
    '''
    def is_odd(n):
        return n % 2 == 1
    tmplist = filter(is_odd, [1,2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13])
    print('打印看看这个迭代器对象',tmplist) # 打印看看这个迭代器对象 <filter object at 0x00000232B9DB8EB8>
    newlist = list(tmplist)
    print(newlist) # [1, 3, 5, 7, 9, 11, 13]
    print('-'*10,"分割线","-"*10)
    
    '''
    float() 函数用于将整数和字符串转换成浮点数。
    class float([x])
    x -- 整数或字符串
    返回浮点数。
    '''
    # 字符串
    print(float('111') ) # 111.0
    print(float(11)) # 11.0
    print('-'*10,"分割线","-"*10)
    
    '''
    Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能。
    基本语法是通过 {} 和 : 来代替以前的 % 。冒号(:)用来格式化字符串;大括号({})用来匹配字符串
    format 函数可以接受不限个参数,位置可以不按顺序。
    '''
    # 不设置指定位置,按默认顺序
    print("{} {}".format("hello", "lidihuo"))
    # 设置指定位置
    print("{0} {1}".format("hello", "lidihuo"))
    # 设置指定位置
    print("{1} {0} {1}".format("hello", "lidihuo"))
    
    #设置参数
    # -*- coding: UTF-8 -*-
    print("网站名:{name}, 地址 {url}".format(name="立地货", url="www.lidihuo.com"))
    # 通过字典设置参数
    site = {"name": "立地货", "url": "www.lidihuo.com"}
    print("网站名:{name}, 地址 {url}".format(**site))
    # 通过列表索引设置参数
    my_list = ['立地货', 'www.lidihuo.com']
    print("网站名:{0[0]}, 地址 {0[1]}".format(my_list))
    
    # 向str.format()传入对象
    class AssignValue(object):
        def __init__(self, value):
            self.value = value
    my_value = AssignValue(10)
    print('value 为: {0.value}'.format(my_value)) # "0" 是可选的
    print('-'*10,"分割线","-"*10)
    
    # 数字格式化
    print("{:.2f}".format(3.1415926))
    print('-'*10,"分割线","-"*10)
    
    
    '''
    floor(x) 返回数字的下舍整数,小于或等于 x。
    import math
    math.floor( x )
    注意:floor()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。
    x -- 数值表达式。
    返回小于或等于 x 的整数。
    '''
    import math # 导入 math 模块
    print("math.floor(-11.17) : ", math.floor(-11.17)) # -12
    print("math.floor(10.12) : ", math.floor(10.12)) # 10
    print("math.floor(10.72) : ", math.floor(10.72)) # 10
    print("math.floor(math.pi) : ", math.floor(math.pi)) # 3
    print('-'*10,"分割线","-"*10)
    
    '''
    frozenset() 返回一个冻结的集合,冻结后集合不能再添加或删除任何元素。
    class frozenset([iterable])
    iterable -- 可迭代的对象,比如列表、字典、元组等等。
    返回新的 frozenset 对象,如果不提供任何参数,默认会生成空集合。
    '''
    a = frozenset(range(10)) # 生成一个新的不可变集合
    print(a) # frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
    # a.add(1) # AttributeError: 'frozenset' object has no attribute 'add'
    b = frozenset('lidihuo')
    print(b) # frozenset({'l', 'o', 'i', 'd', 'u', 'h'})
    print('-'*10,"分割线","-"*10)
    
    '''
    
    '''
    
    努力拼搏吧,不要害怕,不要去规划,不要迷茫。但你一定要在路上一直的走下去,尽管可能停滞不前,但也要走。
  • 相关阅读:
    [置顶] 也论百度轻应用--一个开发者的吐槽
    HDU 1506 Largest Rectangle in a Histogram
    [置顶] 搭建apache+tomcat+memcached集群环境
    (step8.2.6)hdu 1848(Fibonacci again and again——组合博弈)
    SQL2005、2008、2000 清空删除日志
    网络获取北京时间和系统时间
    C++界面库
    Cocos2d-X游戏开发之Windows7+VS2010环境搭建(亲测)
    华为面试题——一道关于指针方面的编程题(C/C++)
    java之Math
  • 原文地址:https://www.cnblogs.com/wkhzwmr/p/15259358.html
Copyright © 2011-2022 走看看