• Day 7 基本数据类型


    一 列表补充 Lists

    需要掌握的其它命令

    index

    Returns the index of the first element with the specified value

    count

    Returns the number of elements with the specified value

    extend

    Add the elements of a list (or any iterable), to the end of the current list

    reverse

    Reverses the order of the list

    sort

    Sorts the list

    二 元组 Tuples

    1.定义 Definition

    Tuples are written with round brackets, elements in tuples are separated by commas

    Notice that you should add a comma in the brackets if there is only one element in a tuple

    A tuple is a collection which is ordered and unchangeable.

    2.作用 Usage

    Tuples are used to store multiple items in a single variable.

    3.优先掌握的操作

    Similar to the previous list

    三 字典 Dictionary

    1.定义 Definition

    A dictionary is a collection which is unordered, changeable and does not allow duplicates.

    Dictionaries are written with curly brackets, and have keys and values,and can be referred to by using the key name.

    2.作用 Usage

    Dictionaries are used to store data values in key:value pairs.

    3.特点 Characteristic

    Changeable

    可变类型

    Unordered

    无序

    Duplicates Not Allowed

    Dictionaries cannot have two items with the same key:

    4.数据转化 Convert

    可以将含有嵌套的部分列表转为字典

    5.需要掌握的操作

    取值 Access items

    You can access the items of a dictionary by referring to its key name, inside square brackets:

    The keys() method will return a list of all the keys in the dictionary

    通过get取值 Access items by "get"

    This method is similar to the previous one, but if the key you input were not in the dictionary, it could return the value "None"

    Update

    Updates the dictionary with the specified key-value pairs

    Setdefault

    Returns the value of the specified key. If the key does not exist: insert the key, with the specified value

    补充了解

    1.深浅拷贝

    Shallow copy and Deep copy

    # from copy import deepcopy
    import copy

    l = [11, 22, [111, 222]]
    new_l = l.copy()
    new2_l = copy.deepcopy(l)
    l[2][0] = 333
    # 改变原列表的字列表中的一个值,观察新列表的变化
    print("原列表", l)
    # 浅拷贝得到的列表会随着原列表而改变
    print("浅拷贝新列表", new_l)
    # 而深拷贝得到的列表不会改变
    print("深拷贝新列表", new2_l)

    2.列表为什么没有find命令

    https://www.cnpython.com/qa/59657

    3.hash

    A hash is a function that converts one value to another. Hashing data is a common practice in computer science and is used for several different purposes. Examples include cryptography, compression, checksum generation, and data indexing.

    Hash算法可以将一个数据转换为一个标志,这个标志和源数据的每一个字节都有十分紧密的关系。Hash算法还具有一个特点,就是很难找到逆向规律。

    具体请见百度百科:

    https://baike.baidu.com/item/Hash/390310?fr=aladdin

  • 相关阅读:
    支持向量机SVM知识梳理和在sklearn库中的应用
    Android P HIDL demo代码编写 (原创)
    Android P HIDL服务绑定模式与直通模式的分析 (原创)
    NFCApplication 启动分析(原创)
    Android native进程间通讯的实例 (原创)
    android 6.0 高通平台sensor 工作机制及流程(原创)
    NFC OMA 访问
    NXP NFC移植及学习笔记(原创)
    自定义View实战
    从0开始学自定义View -1
  • 原文地址:https://www.cnblogs.com/fengshili666/p/14179491.html
Copyright © 2020-2023  润新知