`

python字符串

 
阅读更多

 

#-*- coding:gb18030 -*-

#1. 强制转换为string的三种方式: repr(), str(), ``
print "hello"+repr(" world")
print "hello"+repr(3243241323434) #repr会以合法的方式来表示值
print "hello"+str(32434432343243)
print "hello"+`32412423L`

#2. 尽量用raw_input(),而非input()
#raw_input('输入的任何东西作为原始输入')
#i.e. fsef'fe"
#i.e. fasf"fe'
#i.e. 3

#3. 原始字符串:
#原始字符串在书写正则表达式时非常有用

#(1)普通字符串会把\作为转义符, 原始字符串则不会
print  'C:\nowhere'
print  r'C:\nowhere'

#原始字符串最后一个字符不应该是\, 因为此时python 不清楚是否应该结束字符串
#print  r'C:\nowhere\'

#4.
# Python中的普通字符串在内部是以8位的ASCII码存储的
# Unicode字符串则存储为16位Unicode字符串
print len('hehe')
print len(u'hehe')

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics