区间访问:[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. 解决eclipseMavne的web项目debug时没有源码

  2. 第二章 C#基本数据类型

    第一节 1-关键字和标识符关键字:会不同颜色显示标示符:由字母.中文.数字.下划线组成,不能以数字开头,不能是关键字,不能含有特殊符号,如:@,$思考:下列哪些是合法的标识符?a1.1a.a_b._1 ...

  3. android bitmap的放大缩小

    private static Bitmap big(Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postScale(1.5f,1.5f) ...

  4. 八皇后(dfs+回溯)

    重看了一下刘汝佳的白板书,上次写八皇后时并不是很懂,再写一次: 方法1:逐行放置皇后,然后递归: 代码: #include <bits/stdc++.h> #define MAXN 8 # ...

  5. Cocoapods的安装报错 - Error installing pods:activesupport requires Ruby version >=2.2.2

    1.打开终端 2 移除现有 Ruby 默认源 输入以下指令 $gem sources --remove https://rubygems.org/ 3.使用新的源 输入以下指令 $gem source ...

  6. 关于s:iterator 和s:if 的结合使用

    <s:iterator value="list" status="st"> <div class="sidebar-nav" ...

  7. linux后台运行和关闭、查看后台任务

    转自:http://www.cnblogs.com/kaituorensheng/p/3980334.html fg.bg.jobs.&.nohup.ctrl+z.ctrl+c 命令 一.&a ...

  8. MySQL5.6 on Windows 安装失败: String was not recognized as a valid DateTime

    在Win7,32位上安装MySQL5.6.21时出现日期/时间格式错误, 如下图所示: 错误描述为: String was not recognized as a valid DateTime. 下面 ...

  9. Oracle数据库 控制文件

    一.概念控制文件的主要任务是管理数据库的状态以及描述数据库的物理结构 二.所含有的信息1.数据库名2.数据库标识符(DBID)3.数据库创建时间戳4.数据库字符集5.数据文件信息6.临时文件信息7.在 ...

  10. WPF ItemsControl ListBox ListView比较

    在进行列表信息展示时,WPF中提供多种列表可供选择.这篇博客将对WPF ItemsControl, ListBox, ListView进行比较. 相同点: 1. 这三个控件都是列表型控件,可以进行列表 ...