Python 基础[01]

来源:互联网 发布:access数据库考试重点 编辑:程序博客网 时间:2024/05/16 08:36

“编程语言包括语法和标准库。语法相当于武术招式,而标准库实践经验则类似于内功,需要长期锻炼。Python学习了Java的长处,提供了大量极方便易用的标准库供程序员"拿来主义"。”

[darkni] 这句话不能说 100% 正确,但是对于任何一门编程语言,入门阶段学习语法,然后一段很长的时间内在标准库的寻找、使用上摸打滚爬。内功依旧是数据结构和算法。

(1)Python 的数组地址从 0 开始计数。范围表示左边是闭区间,右边是开区间。

示例:arr = range(10)  

结果:

访问 arr[0] 得到 0访问 arr[1:5] 得到 1,2,3,4

(2)排序和文件操作

排序和文件操作在Coding 时是非常普遍的,记录两篇详细的博客地址:

Python 排序

http://huaxia524151.iteye.com/blog/1169779

Python文件操作读写文件

http://maincoolbo.iteye.com/blog/626655

(3)Slice 切片

seq = [7, 2, 3, 7, 5, 6, 0, 1]
seq[1:5]
[2, 3, 7, 5]

While element at the start index is included, the stop index is not included, so that the number of elements in the result is stop - start.

Either the start or stop can be omitted in which case they default to the start of the sequence and the end of the sequence.

seq[:5]  从 [0,5) 的切片

seq[3:]  从 [3,end) 的切片

seq[-4:] 从倒数第四个到 end 

seq[-6:-2] (共四个元素,-6, -5, -4, -3)


(4)数据结构


[待续...]



0 0
原创粉丝点击