A wrapper class that adds a formatted operation to any valueAnnotations @deprecatedDeprecated (Since version 2.11.0) Use Predef.StringFormatSource StringFormat.scala def formatted(fmtstr: String): String Returns string formatted acco
1.format()格式方法传值时,必须要一一对应,如果不对应则会报错 # format()格式方法传值时,必须要一一对应,如果不对应则会报错 tpl = "i am {},age {},{}".format("seven",18,'alex') print(tpl) #可以通过索引来传值 tpl = "i am {0},age {1},{2}".format("seven",18,'alex') print(tpl) #索引
一,%字符串格式化 1,使用%s 后面一一对应输入对应的字符串,%s可以接受任何参数 print ("I am %s hobby is zhangsan"%'lishi') print ("I am %s hobby is %s"%('lishi','zhangsan')) I am lishi hobby is zhangsanI am lishi hobby is zhangsan 2,%d只能接受数字 msg = "I am %s my age is