zoukankan      html  css  js  c++  java
  • python之格式化

    python有两种方式可以格式化一种是用%s,一种使用format(2.6)进入的,从下面的代码可以看出,效果差不多。

    name = 'edward'
    age = 27
    print("My name is %s and I'm %s years old" % (name, age)) #My name is edward and I'm 27 years old
    print("My name is {} and I'm {} years old".format(name, age)) # My name is edward and I'm 27 years old

    第一种方法值得注意的是:

    s = string   s是万能的,可以代替d和f
    d = digit
    f = float

  • 相关阅读:
    py 5.11
    py 5.10
    py 5.9
    py 5.8
    python 5.7
    python 5.4
    python 5.3
    python 5.2
    python 4.28
    python 4.27
  • 原文地址:https://www.cnblogs.com/lshedward/p/9897766.html
Copyright © 2011-2022 走看看