#format float 3.1415926->3.14
a = 3.1415926
print a
b = float(int(a*100))/100
print b
#string to float
import string
str = "3.1415926"
print str
print string.atof(str)
使用print输出各型的
字符串
整数
浮点数
出度及精度控制
strHello = 'Hello Python'
print strHello
#输出结果:Hello Python
#直接出字符串
1.格式化输出整数
python print也支持参数格式化,与C言的printf似,
strHello = "the length of (%s) is %d" %('Hello World',len('Hello World'))
print strHello
#输出果:the length of (Hello World) is 11
2.格式化输出16制整数
nHex = 0x20
#%x --- hex 十六进制
#%d --- dec 十进制
#%d --- oct 八进制
print "nHex = %x,nDec = %d,nOct = %o" %(nHex,nHex,nHex)
#输出结果:nHex = 20,nDec = 32,nOct = 40
#使用整数的各个制打印同一个数
3.格式化输出浮点数(float)
import math
#default
print "PI = %f" % math.pi
#width = 10,precise = 3,align = left
print "PI = %10.3f" % math.pi
#width = 10,precise = 3,align = rigth
print "PI = %-10.3f" % math.pi
#前面填充字符
print "PI = %06d" % int(math.pi)
#输出结果
#PI = 3.141593
#PI = 3.142
#PI = 3.142
#PI = 000003
#浮点数的格式化,精度、度和
4.格式化输出字符串(string)
#precise = 3
print "%.3s " % ("jcodeer")
#precise = 4
print "%.*s" % (4,"jcodeer")
#width = 10,precise = 3
print "%10.3s" % ("jcodeer")
#输出结果:
#jco
#jcod
# jco
#同于字符串也存在精度、度和。
5.输出列表(list)
l = [1,2,3,4,'jcodeer']
print l
#输出结果:[1, 2, 3, 4, 'jcodeer']
#于list直接打印即可
'''6.出字典(dictionary)'''
d = {1:'A',2:'B',3:'C',4:'D'}
print d
#输出结果:{1: 'A', 2: 'B', 3: 'C', 4: 'D'}
#同python也是支持dictionary出的
6.python print自动换行
print 会自动在行末加上回车,如果不需回车,只需在print语句的结尾添加一个逗号”,“,就可以改变它的行为。
for i in range(0,5):
print i,
或直接使用下面的函数进行输出:
sys.stdout.write("输出的字串")
http://hi.baidu.com/darkroot/blog/item/b80a22ef342e813cacafd5be.html
分享到:
相关推荐
Debug.Print(Format(rs.Fields("工资"), "####.##"))Debug.Print(Format(rs.Fields("工资"), "####.##"))Debug.Print(Format(rs.Fields("工资"), "####.##"))Debug.Print(Format(rs.Fields("工资"), "####.##"))...
介绍了打印报告的编程技巧,直接生成报告格式优美.
CommonPrintProvider wifi实测过,指令内容通用,蓝牙类的自要能连连接上打印机,其他打印步奏基本一致。...void printText(String content, PrintFormat format);//打印文本内容 void printBitmap(Bitmap bitmap, Pr
Print Format$(CHISQ, "#####.##00"); Print " ALAMDA: "; Format$(ALAMDA, ".##E+00") Print Tab(5) Print Tab(3); "A(1) A(2) A(3) A(4) A(5) A(6)" For I = 1 To MA Print Format$(A(I), "#.###0"), Next ...
python教程答案第三章_Python基础教程(第三章) 字符串格式化: format = "hello %s,%s enough for ya" // format称为格式化字符串 value = ('world', 'hot') print format % value 模板字符串: from string ...
今天小编就为大家分享一篇在python中用print()输出多个格式化参数的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
No longer in print format, TPJ remains the quintessential spirit of Perl–a publication for and by Perl programmers who see fun and beauty in an admittedly quirky little language. Games, Diversions, ...
10.在窗体上画一个命令按钮,其名称为Command1,然后编写如下事件过程: Private Sub Command1_Click() a = 12345 Print Format$(a, 000.00) End Sub 程序运行后,单击命令按钮,窗体上显示的是( )。11.确定一个...
First published in print format ISBN-13 978-0-521-89770-9 ISBN-13978-0-511-53367-9 © Cambridge University Press 2009 Information on this title: www.cambridge.org/9780521897709 This publication is...
print "{:.2f}".format(3.1415926) #3.14,保留小数点后两位 print "{:+.2f}".format(3.1415926) #+3.14 带符号保留小数点后两位 print "{:+.2f}".format(-10) #-10.00 带符号保留小数点后两位 print "{:+.0f}".
printf 是 print format 的缩写,意思是“格式化打印”。printf 的返回值是成功打印的字符的个数。 printf("%d",a); d 是 decimal 的缩写,意思是十进制数,%d 表示以十进制整数的形式输出。%d 与 a 是对应的,用 ...
format(format(1.23,"0.00"),"@@@@@@") & " " & format(format(9.5,"0.00"),"@@@@@@") 使用sprintf命令将是 Debug.Print sprintf("%6.2f %6.2f", 1.23, 9.5) 第二种选择显然容易得多,令我惊讶的是,每种语言都没有...
'world')) # 不带字段print('{0} {1}'.format('hello','world')) # 带数字编号print('{0} {1} {0}'.format('hello','world')) # 打乱顺序print('{1} {1} {0}'.format('hello','world'))print('{a} {tom} {a}'.format...
将这个dll放在windows\system32目录下,在VB6中 Private Declare Function mss Lib "mss" () As Long Debug.Print Format(Now, "YYYY-MM-DD hh:mm:ss") + "." + Right("00" + CStr(mss()), 3)
FORMAT 29 GET_DIALOG_VALUE 30 2、扩展函数 31 PRINT_INITA 31 ADD_PRINT_HTML 32 ADD_PRINT_TBURL 32 ADD_PRINT_TEXTA 32 SET_PRINT_STYLEA 32 SAVE_TO_FILE 35 SET_SAVE_MODE 36 SET_PRINT_TEXT_STYLEA 37 ADD_...
format 用法 5、进阶用法 1)进制转换 ...print('{} and {}'.format('hello','world')) # 默认左对齐 print(‘{:10s} and {:>10s}’.format(‘hello’,‘world’)) # 取10位左/右对齐 print('{:^10s}
自述文件 ...xkblayout-state print format 使用以下替换将格式打印到stdout (以包括文字% use %% ): %c >当前活动布局的编号 %n >当前活动布局的名称 %s >当前活动布局的符号 %v >当前活动布局的
顺序传参 strvar = "{}向{}开了⼀枪" res = strvar.format("光头强","熊⼆") print(res) 3.索引传参 strvar = "{1}给{0}⼀个平底锅" res = strvar.format("灰太狼","红太狼") print(res) 4.关键字传参 ''' Python...
目录前言用法通过位置通过关键字填充与对齐精度与类型f进制转化千位分隔符 前言 ...print('{人物}今天{事件}'.format(人\u7269='\u6211',事\u4ef6='\u5199\u535a\u5ba2'))#通过关键字 job = {'perso
如何使用应用选项: usage: [java -jar verilog-format.jar|./verilog-format|verilog-format.exe] [-f ] [-h] [-p] [-s ] [-v] -f,--format <pathname> verilog file -h,--help print this message -p,--print ...