亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

python常用模塊-01

標簽:
Python

1. 简单了解模块

     写的每一个py文件都是一个模块.

    还有一些我们一直在使用的模块

    buildins 内置模块. print, input

    random 主要是和随机相关的内容

        random()    随机小数

        uninform(a,b) 随机小数

        randint(a,b)  随机整数

        choice() 随机选择一个

        sample() 随机选择多个

        shuffle() 打乱

 

2. Collections

    1. Counter 计数器

    2. defaultdict 默认值字典

    3. OrderedDict 有序字典

    数据结构(队列, 栈)

        栈:先进后出

            Stack

class StackFullException(Exception):    passclass StackEmptyException(Exception):    passclass Stack:    def __init__(self,size):
        self.size = size
        self.lst = []
        self.top = 0    def push(self,el):        if self.top >=self.size:            raise StackFullException("超范围了")
        self.lst.insert(self.top,el)
        self.top += 1    def pop(self):        if self.top == 0:            raise StackFullException("拿空了")
        self.top -= 1
        el = self.lst[self.top]        return el

s = Stack(4)

s.push("我")
s.push("和")
s.push("你")
s.push("在")print(s.pop())print(s.pop())print(s.pop())

队列: 先进先出

         Queue

import queue
q = queue.Queue()
q.put("李嘉诚1")
q.put("李嘉诚2")
q.put("李嘉诚3")
q.put("李嘉诚4")
q.put("李嘉诚5")print(q.get())print(q.get())print(q.get())print(q.get())print(q.get())

3. Time模块

    时间有三种:

        结构化时间 gmtime() localtime()

        时间戳  time.time()  time.mktime()

        格式化时间 time.strftime() time.strptime()

        时间转化:

            数字 -> 字符串

            struct_time = time.localtime(数字)

            str = time.strftime("格式", struct_time)

3. Time模块

    时间有三种:

        结构化时间 gmtime() localtime()

        时间戳  time.time()  time.mktime()

        格式化时间 time.strftime() time.strptime()

        时间转化:

            数字 -> 字符串

            struct_time = time.localtime(数字)

            str = time.strftime("格式", struct_time)

   字符串 -> 数字

              struct_time = time.strptime(字符串, "格式")

              num = time.mktime(struct_time)

strt = input("请输入一个时间")
t = time.strptime(strt,"%Y-%m-%d %H:%M:%S")
a = time.mktime(t)print(a)

4. functools

    wraps   给装饰器中的inner改名字

    reduce  归纳.

    偏函数   把函数的参数固定.

作者:small_caier

原文链接:https://www.cnblogs.com/a2534786642/p/10182027.html


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消