美文网首页python
Python 标准库

Python 标准库

作者: 庵下桃花仙 | 来源:发表于2018-07-14 21:14 被阅读27次

很好的python标准库资源网站
https://pymotw.com/3/

Python标准库 是一组模块, 安装的Python都包含它。可使用标准库中的任何函数和类, 为此只需在程序开头包含一条简单import 语句。 下面来看模块collections 中的一个类OrderedDict。
创建字典并记录其中的键—值对的添加顺序

代码

# -*- coding:utf-8 -*-

from collections import OrderedDict # 从模块collections导入OrderedDict类

favorite_languages = OrderedDict() # 创建OrderedDict类的实例。创建空的有序字典

favorite_languages['jen'] = 'python' # 添加名字-语言对
favorite_languages['sarah'] = 'c'
favorite_languages['edward'] = 'ruby'
favorite_languages['phil'] = 'java'

for name, language in favorite_languages.items(): # 遍历favorite_languages
    print name.title() + "'s favorite language is " + \
        language.title() + "."

结果

Jen's favorite language is Python.
Sarah's favorite language is C.
Edward's favorite language is Ruby.
Phil's favorite language is Java.

相关文章

  • (三)python常用标准库

    python常用标准库 python标准库常见模块 操作系统相关:os 时间与日期:time、datetime 科...

  • python3从零学习-5.0、标准库

    Python 标准库 Python 标准库非常庞大,所提供的组件涉及范围十分广泛。这个库包含了多个内置模块 (...

  • Udacity Python 随笔 *

    Udacity Python入门 标准库推荐 Python 标准库的模块很多!为了帮助大家熟悉可用模块,以下是精选...

  • 24.python3标准库

    标准库概览 python3标准库官方文档:https://docs.python.org/zh-cn/3.7/li...

  • 标准库

    标准库 Python标准库中包含了大量有用的模块,同时也是每个标准的Python安装包中的一部分。熟悉Python...

  • Python 标准库

    很好的python标准库资源网站https://pymotw.com/3/ Python标准库 是一组模块, 安装...

  • Python

    教程类 Python 教程 官方教程Python 标准库ctypes --- Python 的外部函数库pyt...

  • python高级编程3

    1.模块进阶 Python有一套很有用的标准库(standard library)。标准库会随着Python解释器...

  • python爬虫脚本下载视频,同时借助FFmpeg合并视频

    requests是简洁的Python http库, 相较Python标准库urllib, requests更加人性...

  • Python操作MySQL

    Python操作MySQL 一. python操作数据库介绍 Python 标准数据库接口为 Python DB-...

网友评论

    本文标题:Python 标准库

    本文链接:https://www.haomeiwen.com/subject/oexupftx.html