区间访问:[from:to:step]

  1. step默认是1;from表示起始索引(包括),to表示结束索引(不包括)
  2. step如果有符号,表示方向从右到左;
  3. from,to有符号,表示从倒数开始算,如-3表示倒数第三个
  4. string是特殊的类型,且是元组,不能修改;
  5. 对list添加元素,不能像JS一样,要使用append(item)函数

 

# [from:to:step] from include,to not include,step default is 1. ( Nagetive sign refer than the direction is from right to left.)

 

s1 = (2, 1.3, 'love', 5.6, 9, 12, False)

s2 = [True, 5, 'smile']

 

print s1==s1[:] #default is the list

print s1[:5] # 前5个

print s1[2:] # 从第3开始

 

print s1[0:5:2] #每两个

 

print s1[2:0:-1] # not include s1[0] ,because 0 is the TO.

 

 

# 倒序引用

 

print s2[-1]

print s2[1] == s2[-2]

 

# String is a tuple ,can't modify the char.

str = 'abcdef'

print str[2:4],type(str)

#str[0] = 'z' will throw

 

# 添加元素,需要调用 append

s2.append('pzdndd')

print s2[-1] == 'pzdndd'

 

数学 +, -, *, /, **, %

判断 ==, !=, >, >=, <, <=, in

逻辑 and, or, not

print 3**4 # 乘方 81

 

print 5 in [1,3,5] #

 

print
True
and
False

print
True
or
False

print
not
True

Python学习笔记03的更多相关文章

  1. python学习笔记03 --------------程序交互与格式化输出

    1.读取用户输入内容 语法:input() 例: name = input('你的名字是?) print('你好'+name) 程序会等待用户输入名字后打印:你好(用户输入的名字) 注意:input接 ...

  2. python学习笔记03:python的核心数据类型

    从根本上讲,Python是一种面向对象的语言.它的类模块支持多态,操作符重载和多重继承等高级概念,并且以Python特有的简洁的语法和类型,OOP十分易于使用.Python的语法简单,容易上手. Py ...

  3. Python 学习笔记03篇

    看着直播,想着未赶完的工作 真的很想学好一门编程语言

  4. Python运算符(Python学习笔记03)

  5. OpenCV之Python学习笔记

    OpenCV之Python学习笔记 直都在用Python+OpenCV做一些算法的原型.本来想留下发布一些文章的,可是整理一下就有点无奈了,都是写零散不成系统的小片段.现在看 到一本国外的新书< ...

  6. Python学习笔记,day5

    Python学习笔记,day5 一.time & datetime模块 import本质为将要导入的模块,先解释一遍 #_*_coding:utf-8_*_ __author__ = 'Ale ...

  7. 机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理、源码解析及测试

    机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理.源码解析及测试 关键字:决策树.python.源码解析.测试作者:米仓山下时间:2018-10-2 ...

  8. OpenCV 学习笔记03 findContours函数

    opencv-python   4.0.1 1 函数释义 词义:发现轮廓! 从二进制图像中查找轮廓(Finds contours in a binary image):轮廓是形状分析和物体检测和识别的 ...

  9. 雨痕 的《Python学习笔记》--附脑图(转)

    原文:http://www.pythoner.com/148.html 近日,在某微博上看到有人推荐了 雨痕 的<Python学习笔记>,从github上下载下来看了下,确实很不错. 注意 ...

随机推荐

  1. 常用js函数整理--common.js

    var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data: data, dataType: 'json ...

  2. oracle默认配置ora文件位置

    unix:$ORACLE_HOME/dbsnt:c:\Oracle\ora81\database create spfile from pfile = '/home/oracle/initora11g ...

  3. iOS 语录

    1. 输入法切换: cmd + space 2. xcode 退出全屏control + cmd + f 3. xcode 代码格式化插件Uncrustify,XAlign, CLangFormat ...

  4. EasyUi – 2.布局Layout + 3.登录界面

    1.页面布局 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.a ...

  5. MVC – 5.MVC设计模式和.NetMVC框架

    MVC模式-设计模式 •控制器(Controller)- 负责转发请求,对请求进行处理. •视图 (View) - 界面设计人员进行图形界面设计. •模型 (Model)-业务逻辑.数据.验证规则.数 ...

  6. @ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4 "/" $NF}'中"[ :]+" 是什么意思?@

    http://blog.csdn.net/zhuying_linux/article/details/6822987

  7. Delphi中exit、break、continue等跳出操作的区别

    Delphi中表示跳出的有break,continue,abort,exit,halt,runerror等 1.break 强制退出最近的一层循环(注意:只能放在循环里:而且是只能跳出最近的一层循环) ...

  8. HDU5556 Land of Farms(二分图 2015 合肥区域赛)

    容易想到将问题转化为求图的独立数问题 ,但求一般图的独立集是一个NPC问题,需要一些转化. 状态压缩,枚举每个上古农场是否选择,然后将剩下的新农场根据i + j奇偶性分为x , y集. 结果为 max ...

  9. phpcms_v9 多图字段 内容页,首页,分页自定义字段调用

    phpcms_v9 多图字段 内容页,首页,分页自定义字段调用 说明:自定义多图字段名 shigongtu 1 内容页调用 {loop $shigongtu $r}      <img src= ...

  10. VS2012 OpenCV2.4.9 Debug可以允许,Release不可以

    一个简单的程序 #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgu ...