zoukankan      html  css  js  c++  java
  • Python学习笔记03

     

    区间访问:[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

  • 相关阅读:
    [Install] TeamViewer
    [2017
    [2017 ACL] 对话系统
    [2018 ACL Short and System] 对话系统
    Git分支创建与合并
    Git常用命令
    JSONObject转换分析
    数据库行锁实现
    Jenkins安装
    Tomcat热部署,Web工程中线程没有终止
  • 原文地址:https://www.cnblogs.com/pengzhen/p/4704912.html
Copyright © 2011-2022 走看看