haibaraxx的个人博客分享 http://blog.sciencenet.cn/u/haibaraxx

博文

Python 2: strings

已有 1424 次阅读 2016-11-17 23:02 |个人分类:Python|系统分类:科研笔记| strings

# double or single quotes

>>> 'hey yy'
'hey yy'


>>> "hey yy"
'hey yy'


>>> "he's a handsome man"
"he's a handsome man"


>>> 'he's a handsome man'
"he's a handsome man"


>>> 'he said,"shop!"'
'he said,"shop!"'


>>> "he said,"shop!""
'he said,"shop!"'


>>> a='Jane'
>>> b='Eyre'
>>> a+b     # + concatenate strings
'JaneEyre'
>>> a,b
('Jane', 'Eyre')
>>> c='Jane '  # Note the backspace!
>>> c+b
'Jane Eyre'


>>> a='Kamm'
>>> a*5 # * repeat strings
'KammKammKammKammKamm'
>>> b='Tag ' # Note the backspace!
>>> b*3
'Tag Tag Tag '


# convert any format of an element to string using `` and str()

>>> a=18

>>> print 'yy is ' + `a` # The backtick sign `(重音符号)  is right below the tilde ~ (波浪符号) on the keyboard.
yy is 18
>>> print 'yy is ' + str(a)
yy is 18



https://blog.sciencenet.cn/blog-3031432-1015390.html

上一篇:Python 3: Module math - mathematical functions
下一篇:Python 2: index and change elements of variables
收藏 IP: 134.1.1.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-2 05:35

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部