您的位置:首页 > 编程语言 > Python开发

python 开发中易混淆点

2015-11-23 13:34 561 查看
1.for 循环

#coding = utf-8
count = 0
for i in range(8):
count += 1
i = i+ 2
print count
>>> 8


count的值为8说明循环了8次,循环的次数并不因为我们在循环中改变i的值改变,即在循环中改变i的值没有意义

2."" -------->表示空字符串

" " ---------->表示有一个空格元素的字符串

3.字符串的find方法

>>> "".find("a")
>>> -1

>>> "abc".find('')
>>> 0
空的字符串也可以调用find()方法

4.字符串的分片操作 VS 索引操作

>>>ss = "asdfg"
>>>aa = ss[1:8]
>>>aa
>>>"sdfg"

>>>ss[5:8]
""

>>>ss[8]
IndexError: string index out of range
5.list的append()用法

>>>res=[]
>>>res.append(5+3)
>>>res.append(5+3*2)
>>>res
[8,11]
append的参数可以是表达式
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: