3.7.7 - String Formatting
来源:互联网 发布:网上开淘宝店流程 编辑:程序博客网 时间:2024/05/18 00:49
a = 1b = 2c = 4.32456#Use the format method to replace {0} with the sum of a + b"The sum of a + b is {0}".format(a + b)"a: {0} b: {1} c: {2}".format(a, b, c)"a: " + str(a) + " b: " + str(b) + " c: " + str(c)"a:{0:04d}".format(a)"c: {0:0.2f}".format(c)"The sum of a + b is %s" % ( a + b)"c: %0.2f" % (c)
运行结果如下:
"The sum of a + b is {0}".format(a + b)
// Result: The sum of a + b is 3 //
"a: {0} b: {1} c: {2}".format(a, b, c)
// Result: a: 1 b: 2 c: 4.32456 //
"a: " + str(a) + " b: " + str(b) + " c: " + str(c)
// Result: a: 1 b: 2 c: 4.32456 //
"a:{0:04d}".format(a)
// Result: a:0001 //
"c: {0:0.2f}".format(c)
// Result: c: 4.32 //
"The sum of a + b is %s" % ( a + b)
// Result: The sum of a + b is 3 //
"c: %0.2f" % (c)
// Result: c: 4.32 //
%() 类似.format()
0 0
- 3.7.7 - String Formatting
- String Formatting in C#
- String Formatting in C#
- String Formatting with %
- Formatting String Objects
- String Formatting Operator
- 【Python】Advanced String Formatting
- 字符串格式化(String Formatting)_C#
- Formatting
- not all arguments converted during string formatting
- not all arguments converted during string formatting
- Java for Complete Beginners StringBuilder and String Formatting
- not all arguments converted during string formatting 解决
- TypeError: not all arguments converted during string formatting
- TypeError: not all arguments converted during string formatting
- TypeError: not all arguments converted during string formatting问题解决
- (完)learn python第五章:更多类 (第七节:字符串格式化string formatting)
- formatting messagebox
- 黑马程序员——Java基础语法——数组和循环嵌套
- JAVA 的 SHA-256 和 SHA-512 两种 Hash 算法的调用
- 3.7.6 - String Methods
- 工厂模式
- uboot - 主Makefile分析【3】
- 3.7.7 - String Formatting
- 黑马程序员——Java基础——面向对象
- 3.8 - Using the Print Function
- Android-xml解析之PULL解析
- 3.9.1 - Lists in Python
- Struts2中Action的属性接收参数
- BytesWritable使用
- 学那么多东西有屁用,不如先建立自己的知识体系
- 3.9.2 - Lists - Adding and Removing Objects