zoukankan      html  css  js  c++  java
  • 内置函数-format()

    # 字符串串
    print(format('test', '<20')) # 左对⻬齐
    print(format('test', '>20')) # 右对⻬齐
    print(format('test', '^20')) # 居中
    # 数值
    print(format(3, 'b')) # ⼆二进制
    print(format(97, 'c')) # 转换成unicode字符
    print(format(11, 'd')) # ⼗十进制
    print(format(11, 'o')) # ⼋八进制
    print(format(11, 'x')) # ⼗十六进制(⼩小写字⺟母)
    print(format(11, 'X')) # ⼗十六进制(⼤大写字⺟母)
    print(format(11, 'n')) # 和d⼀一样
    print(format(11)) # 和d⼀一样
    # 浮点数
    print(format(123456789, 'e')) # 科学计数法. 默认保留留6位⼩小数
    print(format(123456789, '0.2e')) # 科学计数法. 保留留2位⼩小数(⼩小写)
    print(format(123456789, '0.2E')) # 科学计数法. 保留留2位⼩小数(⼤大写)
    print(format(1.23456789, 'f')) # ⼩小数点计数法. 保留留6位⼩小数
    print(format(1.23456789, '0.2f')) # ⼩小数点计数法. 保留留2位⼩小数
    print(format(1.23456789, '0.10f')) # ⼩小数点计数法. 保留留10位⼩小数
    print(format(1.23456789e+10000, 'F')) # ⼩小数点计数法.
    
  • 相关阅读:
    贪婪算法、递归计算、动态规划背包问题
    递归、动态规划计算斐波那契数列
    用于确定两个字符串最长公共子串的函数
    快速排序算法
    顺序、二分查找文本数据
    MyBatis面试题
    Spring面试题
    SpringMvc面试题
    jsp和servlet面试
    EJB的理解
  • 原文地址:https://www.cnblogs.com/fan-gx/p/12812228.html
Copyright © 2011-2022 走看看