>>> myString = 'hello world !' 
>>> print myString						# print语句会调用str()函数
hello world !
>>> myString							# 直接使用变量名,输出的字符串是用单引号括起来的。其实,交互式解释器调用的是repr()函数
'hello world !'
>>> _								  # _在解释器中有特殊含义,表示最后一个表达式的值
'hello world !'


">>"重定向输出:

>>> logfile=open('/tmp/mylog.txt','a')
>>> print >> logfile,'just a test !'
>>> logfile.close()
>>> 
# more /tmp/mylog.txt 
just a test !

 

相关文章:

  • 2021-07-04
  • 2021-07-28
  • 2022-01-11
  • 2022-12-23
  • 2021-04-17
  • 2021-11-11
猜你喜欢
  • 2021-10-09
  • 2021-10-22
  • 2021-05-23
  • 2022-01-18
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案