1. range()函数的使用:

a = range(n)   # a = range(0,n)
b = range(m,n) # b = range(m,n)

alist = list(a) # alist = [0, 1, ... , n-1]
blist = list(b) # blist = [m, m+1, ... , n-1]
#notice: 均不包含n,即类似左闭右开的区间形式 [... ...)

2. import ... 与  from ... import * 的区别:

#使用numpy包含的模块时需要在前面加np
import numpy as np
a = np.array([1, 2, 3, 4])
#直接调用numpy包含的模块
from numpy import *
a = array([1, 2, 3, 4])

3. list列表操作

#获取长度
listLen = len(sampleList)
#遍历list中元素
for element in list:
print(element)
#删除元素
del sampleList[2:4]
#浅拷贝与深拷贝
lista = [1, 4, 2, 5, 3]
listb = lista
listc = lista[:] lista.sort() # lsita = [1, 2, 3, 4, 5]
print(listb) # listb = [1, 2, 3, 4, 5]
print(listc) # listc = [1, 4, 2, 5, 3]
sample_list.append(var)   #追加元素
sample_list.insert(index,var)
sample_list.pop(var) #返回最后一个元素,并从list中删除之
sample_list.remove(var) #删除第一次出现的该元素
sample_list.count(var) #该元素在列表中出现的个数
sample_list.index(var) #该元素的位置,无则抛异常
sample_list.extend(list) #追加list,即合并list到L上
sample_list.sort() #排序
sample_list.reverse() #倒序

4. 判断数据类型 if type(sample)==type(1):         #判断sample是否为int

5. 格式化输出 print("The sample number is %d and %f" %(4,2))  #The sample number is 4 and 2.000000

6. 条件选择  if: ... elif: ...

7. 绘制散点图 (matplotlib官网给出了大量绘图样例,非常棒,想要绘制图形可以参考)

matlbplot的plot函数,很好用,与matlab中的plot类似

8. python的在传递list时使用的是引用(reference),因此如果list的值在一个函数中被改变,则它在所有地方都会是改变后的值。

9. 集合类型(set):一无序不重复元素集。基本功能包括关系测试和消除重复元素

a = [1, 2, 3, 3, 4, 5, 5]
b = set(a) #b = set([1, 2, 3, 4, 5])
setA = set([1 ,2 , 3, 4])
setB = set([3 ,4 , 5, 6])
setC = setA | setB # 并集 setC = set([1, 2, 3, 4, 5, 6])
setC = setA & setB # 交集 setC = set([3, 4])
setC = setA - setB # 差集 setC = set([1, 2])
setC = setA ^ setB # 对称差集 setC = set(1, 2, 5, 6)

10. 排序函数sorted与sort

from operator import itemgetter, attrgetter  

list_a = [1, 5, 4, 2, 3]
list_a.sort() # list_a = [1, 2, 3, 4, 5]
list_b = sorted(list_a, reverse = True) # list_b = [5, 4, 3, 2, 1] list_a = [("li si", "D", 12), ("xiao ming", "A", 15), ("ma zi", "A", 14), ("wang er", "B", 10)]
list_b = sorted(dic_a, key = itemgetter(1, 2), reverse = True)
# sort by grade then by age 
# list_b = [("li si", "D", 12), ("wang er", "B", 10), ("xiao ming", "A", 15), ("ma zi", "A", 14)]

Python notes的更多相关文章

  1. Core Python Notes

    开发需要在读 Python 核心编程,一些 Point 记录如下. ******************************************** 版本相关 标准版的 Python 是用 C ...

  2. 初识python notes

    python数据类型 数字 字符串 列表 元祖 字典 1.为什么要编程 编程的目的是解放人力,这就需要人通过编写程序的方式计算机代替人去自动干活 2.什么是编程语言 编程语言就是人与计算机之间沟通的介 ...

  3. Python Notes | Python 备忘笔记

    [ File IO ] parameters used in the file IO: 该参数决定了打开文件的模式:只读,写入,追加等.所有可取值见如下的完全列表.这个参数是非强制的,默认文件访问模式 ...

  4. Python字节流打包拆包

    Python提供了一个struct模块用于打包拆包 -------------------------------------------------------------------------- ...

  5. python基础知识十一

    图形软件 使用Python的GUI库——你需要使用这些库来用Python语言创建你自己的图形程序.使用GUI库和它们的Python绑定,你可以创建你自己的IrfanView.Kuickshow软件或者 ...

  6. python from entry to abandon4

    python from entry to abandon系列的收官之作    本篇博客将会介绍<简明Python教程>的最后四章内容.并在最后附上对于本书的个人评价和下阶段自学Python ...

  7. Python(三)基础篇之「模块&面向对象编程」

    [笔记]Python(三)基础篇之「模块&面向对象编程」 2016-12-07 ZOE    编程之魅  Python Notes: ★ 如果你是第一次阅读,推荐先浏览:[重要公告]文章更新. ...

  8. Python(四)基础篇之「文件对象&错误处理」

    [笔记]Python(四)基础篇之「文件对象&错误处理」 2016-12-08 ZOE    编程之魅  Python Notes: ★ 如果你是第一次阅读,推荐先浏览:[重要公告]文章更新. ...

  9. QGIS 2014年7月18日版本

    4. Building on Windows 4.1. Building with Microsoft Visual Studio This section describes how to buil ...

随机推荐

  1. Leetcode: Valid Word Abbreviation

    Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...

  2. Qt4.8.5在ARM9上的移植

    Qt4.8.5在ARM9开发板上的移植 以前移植过qtopia-embedded-2.2.0,俗称Qt/E,在早期的Qt框架中是使用X11桌面服务器系统,无法应用于嵌入式平台,为此产生了qtopia, ...

  3. Java程序员学习之路

    1. Java语言基础 谈到Java语 言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的相当深刻的技术书籍,Java语言基础部分基 ...

  4. 夺命雷公狗-----React---17--事件常用的属性

    我们可以通过打印的方式将他打印出来看看,如下所示: <!DOCTYPE> <html> <head> <meta charset="utf-8&qu ...

  5. [Struts2] Action Implements SessionAware

    struts2 的Action中若希望访问Session对象,可采用两种方式: 1.从ActionContext中获取: 2.实现SessionAware接口. 1.从ActionContext中获取 ...

  6. mbed学习之 PWMOUT

    PWM通过一个周期内不同占空比来表征模拟量,应用非常广泛.mbed中提供了一个PWM类,来对PWM进行操作,可以分别设置占空比,周期,以及脉冲宽度. 因为这里是使用单片机内部TIM来生成PWM波的,所 ...

  7. linux下使用远程图形界面

    1. 用xrdp的方式(客户端就是windows下的远程桌面程序) http://jingyan.baidu.com/article/d3b74d64bdab5d1f76e60951.html 2. ...

  8. bitnami redmine每日自动备份

    主要思路:在半夜时停止服务,进行完整备份,然后再开启服务. 1.主脚本backup.bat: call backup-stopserver.batping /n 20 127.1 >nul ca ...

  9. 谷歌 HTML/CSS 规范 2016-12-30

    背景 这篇文章定义了 HTML 和 CSS 的格式和代码规范,旨在提高代码质量和协作效率. 通用样式规范 协议 省略图片.样式.脚本以及其他媒体文件 URL 的协议部分(http:,https:),除 ...

  10. EBS learning history (to know about the environment)

    prcsgidb1: /u01/Stage/database C:\Users\alley_li>ping prcsgidb1 Pinging prcsgidb1.ad.infosys.com ...