• python format


    //test.py

    print "{} {}".format("hello", "world")

    print '{0} {1}'.format('hello', 'world')

    print '{1} {0} {1}'.format('hello', 'world')

    print 'website: {name}, addr: {url}'.format(name='zcl', url='www.zcl.com')

    site = {'name':'zcl', 'url':'www.zcl.com', 'other':'guess'}

    print 'website: {name}, addr: {url}, other: {other}'.format(**site)

    _list = ['zcl', 'www.zcl.com']

    print 'website: {0[0]}, addr: {0[1]}'.format(_list)

    print ('{:.2f}'.format(3.1415926))

    print ('{:+.2f}'.format(3.1415926))

    print ('{:b}'.format(11))

    class AssignValue(object):

            def __init__(self, value):

                    self.value = value

    my_value = AssignValue(6)

    print 'value is :{0.value}'.format(my_value)

    print 'end'

    //result

    # python test.py
    hello world
    hello world
    world hello world
    website: zcl, addr: www.zcl.com
    website: zcl, addr: www.zcl.com, other: guess
    website: zcl, addr: www.zcl.com
    3.14
    +3.14
    1011
    value is :6
    end

  • 相关阅读:
    Scala_模式匹配
    Scala_特质
    Scala_继承
    Scala_对象
    Scala_类
    Scala_关键字
    Scala_数据结构
    Scala_方法、函数、柯里化
    Scala_控制结构
    Scala_基本语法
  • 原文地址:https://www.cnblogs.com/woodzcl/p/7833818.html
Copyright © 2020-2023  润新知