Python 使用字符串,python使用字符串,如下代码演示Python


如下代码演示Python如何使用字符串

#!/usr/bin/python# 用单引号表示字符串,字符串内的单引号要做转义s1 = 'I\'m single'# python中也可以用双引号表示字符串s2 = "I'm double double"# python可以用三个单引号或者双引号包括多行文本的字符串s3 = '''I'm very long-winded and I really needto take up more than one line.  That way I can say all the very`important' things which I must tell you.  Strings like me are usefulwhen you must print a long set of instructions, etc.'''# 字符串之间用空格分隔s4 = 'left' "right" 'left'# 用加号做字符串相加操作s5 = s1 + "\n" + s2print s5 + '\n' + s3, "\n", s4print 's5 has', len(s5), 'characters'

评论关闭