day04 essays - basic data types

Python basis (day04)

Basic data types

  1. Digital Type

    Action: storing digital, or mathematical operation for counting

    Defined manner: a = 1; a = int (1)

    Usage: + Addition - Subtraction * Multiplication /% // modulo a power of other rounding **

  2. String type

    Role: storing character

    Defined method: s = 'str'; s = '' str ''; s = '' 'str' ''; s = str ( 'str')

    Usage: string can be added between the

    And may be represented by a number n * string with repeated n times

  3. List

    Action: as a container for storing a plurality of elements, the elements may be different data types

    Defined manner: a = [1,2,3,4,5,6, 'a', 8]

    ​ a=list('handsome sheppard')

    Usage: a = list ( 'handsome sheppard')

    ​ a[:2]=>['h', 'a']

    ​ a[-4:]=>['p', 'a', 'r', 'd']

  4. dictionary

    Action: key index may be (key may be integer, floating point, tuple, string) value storage, can store a plurality of key: value element

    Defined method: dic = {key: value}

    Usage: dic = {}

    ​ dic['name']='sheppard'

    ​ print(dic)====》{'name': 'sheppard'}

  5. Boolean

    Action: determination logic

    Defined method: bol = True; bol = bool (1)

    Usage: print (1 == 2) == "False

    In addition to the python 0 / None / null / False values ​​of all comes with Boolean True

Decompression operation

If we give a list lis = [ 'sheppard', 'male', '180'], we need to remove a plurality of disposable values, which requires use of a decompression operation.

name_list = ['sheppard', 'male', '180']
x = name_list[0]
y = name_list[1]
z = name_list[2]
print(f'x:{x}, y:{y}, z:{z}'

==>x:sheppard,y:male,z:180

If only part of the time needed, some values ​​are not what we want, then use universal underscore

lis = ['sheppard', 'male', '180']

_,y,z=lis 

==>y='male';z='180'

* _ Represents may also be used in the whole process will be omitted

  *_,z=lis

==>z='180'

== Also note that the dictionary can also decompress, but decompression is key ==

info={'name':'sheppard','sex':'male','height':'180','weight':'160'}

a,b,c,d=info

==>a='name';b='sex';c='height';d='weight'

Guess you like

Origin www.cnblogs.com/Sheppard/p/11271920.html