python学习笔记(一)

字符串

1.python中字符串连接使用"+"

text1 = 'hello'
text2 = ' world'
print text1+text2     //hello world

2.字符串表示
在python中将值转换为字符串有三种机制
Ⅰ.repr() ,将值以合法形式的Python表达式来表示值;

print 'hello world'   // hello world
print 1000L           // 1000

直接打印出来的结果是不带双引号或者没有类型符的,如果使用repr()

print repr('hello world')     //'hello world'
print repr(1000L)             //1000L

说明使用repr()就能将值转换为python合法形式表达式的字符串。
Ⅱ.str(),将值转换为合理形式的字符串;

print str(1000L)              //1000
print str('hello world')      //hello world

Ⅲ.使用``将值包住也可以实现repr()的效果。
3.input()与raw_input()
input默认输入的值是合法的python表达式。

input('how are you?')
>>>how are you? fine          //name 'fine' id no defined

raw_input会将输入的数据当做原始数据。

raw_input('how are you?')
>>>how are you? fine          // 'fine'

4.长字符串
使用```来代替引导就可以实现长字符串,长字符串可跨多行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值