您的位置:首页 > 编程语言 > Python开发

python笔记-字符串

2016-01-12 15:16 525 查看
>>> 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 !
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: