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')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值