zoukankan      html  css  js  c++  java
  • 程序媛计划——python初级class5~13

    列表和元组都是可迭代对象(可以用于for in)

    列表 []

    #添加列表元素:

    list.append(argu)

    #修改列表:

    list[2] = 2017

    #删除列表元素

    Del list[2]

    #获取列表长度

    len(list)

    #组合列表

    >>>[1,2,3]+[4,6]

    [1,2,3,4,6]

    #定义有周期性的列表

    [100,]*4==[100,100,100,100]

    元组()

    特点:元组中的元素不能修改

    #创建元组

    Tup1 = (‘apple’,’ip’,2016,2017)

    tup2=‘x’,’y’,’z’

    #创建空元组

    Tup = ()

    #创建只含有一个元素的元祖

    Tup =(1,)

    #对元组进行连接组合

    tup3 = tup1+tup2

    #删除整个元组(不能删除元组中的元素)

    Del tup3

    #获取元组长度

    len(tuple)

    #获取有周期性的元组

    (100,)*4==(100,100,100,100)

    字典{}

    特点:key必须是不变对象,如str,num或者tuple;同一个key不能出现两次,如果定义时有两个相同的key,相应的后一个value会覆盖前一个

    #define

    D = dict(name =‘bob’,age =20)

    D ={‘apple’:’苹果’,‘banana‘:’葡萄‘}#key是不可变对象字符串,要带引号

    #通过key获取value

    d= {‘name’:’Jane’, ‘sex’:’female’}

    print d[‘sex’]

    #修改value

    d[‘name’] = ‘bob’

    #添加新key-value

    d[‘height’] = 163

    #del key-value

    d[‘sex’] = ‘female’

    #del all dict

    d.clear() #删除后d变成空字典

    del d #字典被彻底删除,再使用时会报错

    #返回字典中的所有键key/value

    dict.keys()

    dict.values()

    Class10~13

    时间和日期

    #返回1970年1.1午夜到现在的时间秒数

    Import time

    Print time.time()

    #返回现在从年到秒的时间

    Print time.localtime(time.time())

    #返回有一定格式的当前从年开始到秒到时间

    time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())#前面的格式化字符串取的是time.localtime()函数的中时间日期格式化符号对应的数据;前面这些Ymd……是py中时间日期格式化符号

    #返回月历

    import calendar

    print calendar.month(2017,9)

    Console:

       September 2017

    Mo Tu We Th Fr Sa Su

                 1  2  3

     4  5  6  7  8  9 10

    11 12 13 14 15 16 17

    18 19 20 21 22 23 24

    25 26 27 28 29 30

    #返回当天所属星期

    import time

    print time.strftime('%a',time.localtime())

    函数()

    函数中return是函数结束的标志,所以执行了一个return 就直接结束不会再执行下面代码的return了。

    函数不一定要有return语句

  • 相关阅读:
    ListView自定义滑动条
    使用天天模拟器开发Android应用
    自定义对话框
    显示下载进度
    PullToRefresh的使用
    Cookie
    Servlet
    HTTP
    svn
    转:MAVEN常用命令
  • 原文地址:https://www.cnblogs.com/IcarusYu/p/7482896.html
Copyright © 2011-2022 走看看