标签:
>>> num=input(‘n:‘) n:1234 >>> print(‘sdf:‘,n) Traceback (most recent call last): File "<pyshell#72>", line 1, in <module> print(‘sdf:‘,n) NameError: name ‘n‘ is not defined >>> print(‘sdf:‘,num) sdf: 1234 >>> print(‘sdf:‘,int(num)) sdf: 1234 >>> print(‘sdf:‘,int(num)*2) sdf: 2468 >>> print(‘sdf:%d‘,int(num)*2) #前有%d,后用的逗号,没用%:%d当做字符输出了 sdf:%d 2468 >>> print(‘sdf:%d‘%int(num)*2) sdf:1234sdf:1234 >>> print(‘sdf:%d‘%int((num)*2))) SyntaxError: invalid syntax >>> print(‘sdf:%d‘%(int((num)*2))) sdf:12341234 >>> print(‘sdf:%d‘%(int(num)*2)) sdf:2468 >>> >>> print(‘sdf:‘%int(num)*2) #后面有% 没用逗号,而前面没有%,错误 Traceback (most recent call last): File "<pyshell#84>", line 1, in <module> print(‘sdf:‘%int(num)*2) TypeError: not all arguments converted during string formatting >>> print(‘sdf:‘%(int(num)*2)) Traceback (most recent call last): File "<pyshell#85>", line 1, in <module> print(‘sdf:‘%(int(num)*2)) TypeError: not all arguments converted during string formatting >>>
原图:
#int(num)没括号不行
>>> print(‘sdf:%d‘%int num*2) SyntaxError: invalid syntax >>> print(‘sdf:%d‘%int num) SyntaxError: invalid syntax >>>
原图: #int(num)没括号不行; #字符串*2
标签:
原文地址:http://www.cnblogs.com/hhj187/p/4607180.html