********************************Part1:list*******************************

 

#############deep gray magic#############

"""

# v=[1,2,3,'age',[1,2,3,['df',23]],12,True]

 

# ******* index *******

# modify

# v[1]='zxver'

# delete

# del v[5]

# print(v)

 

# ******* slice *******

# modify

# v[1:3]='zxver',20

# delete

# del v[3:6]

# print(v)

 

# in operation

# v1 = 2 in v

# print(v1)

 

# Switch to list :use for circulation inside

   # string to list :li = list('sjdhbdbdb')

# if s = 123

# li = list(s) : report wrong

 

# list switch to string

# method1: write a for program

s = ""

li = [11,22,33,'alex']

for ai in li:

    s = s + str(ai)

print(s)

 

 # method 2:if just include string

li = ["alex","edon","123"]

v = "".join(li)

print(v)

"""

# Parameter :

    # 1: append

# li = [11,22,33]

"""

# v = li.append(25)

# v = li.append('alex')

v = li.append([12,34,66])

print(v)  # >>>>none

print(li)

 

    #2: clear

li.clear()

print(li)

 

    #3: copy:shallow coppy

v = li.copy()

print(v)

 

    #4: count : must include parameter in the bracket

m = li.count(22)

print(m)

 

    #5: extend : the parameter must be iterable

li.extend([9988,"srtf"])

# [11, 22, 33, 9988, 'srtf']

# compared with appened

li.append([9988,"srtf"])

print(li)

# [11, 22, 33, 9988, 'srtf', [9988, 'srtf']]

 

    #6: index: find the place of the character

vi = li.index(22,0,2)

print(vi)

 

    #7: insert

vi = li.insert(0,267)

print(li)

 

    #8: pop: delete the certain character and get the valnue ; delete the last one by default

vi = li.pop()

print(li). #[11,22]

print(vi). # 33

 

    #9: remove: remove the appointed characeter from the list

vi = li.remove(22)

print(li)

 

########5 kinds of delete centence########

# pop   remove   del(index/slice) clear

  

    #10: reverse

li. reverse()

print(li)

"""

    #11: sort: rank the list from small to big by default

 

li = [11,45,2,78,99]

# li.sort()

li.sort(reverse=True)

# from the big to small

print(li)

 

 # owe:cmp  key  sorted

 

********************************Part2:Tuple*******************************

"""

#####the relation with list and tuple #####

list 

li = [11,22,33]

tu = (11,22,33,[(33,55)],(),True,89,)

# get 33

v = tu[3][0][0]

print(v)

#************tuple Notition************

### 1:the first stage can not be modified:no add or delete But can modify the inner parameter such as tu[3][0] = 568 it's ok

### 2:Normally add a comma in the end

 

# tu = (11,22,33,[],(),True,89,)

# v = tu[1]

# v = tu[1:5]

# for item in tu:  # can use for; iterable(use for switch;for;extend...)

    # print(item)

 

tu = ('sd','shxh')

# join: all are string

v = "_".join(tu)

print(v)

######*****Switch between the 3 type*******

 

tu = ('shhdh',233,'dhdh',True,)

li = ['shhdh',233,'dhdh',True]

s = 'djdjjnsbh'

v = list(tu)

print(v)

 

v1 = tuple(li)

print(v1)

"""

#. tu.count(22)

#. tu.index(22)

 

********************************Part3:Dictionary*******************************

###### *********dict*************

     # key:value

     # key:except the  list;booleans(0,1);dict

     # value can be any type

 

info = {

     "k1":"v1",   

     "k2":123,

     "k4":['sd',

            223,

            'rrfr',

            [],

            (),

            {

             "k1":"v1",   

             "k2":123,

             "k3":(12,34)

     }

     ]

                  

}

"""

# print(info)

# dict have no sequence

# index :find the charecter and the same use of delete

 

# v = info["k1"]

# v = info["k4"][5]["k3"][0]

# del info["k4"][5]["k3"]

 

# for while

#  get the keys

# for item in info:

# default= for item in info.keys(): 

 

# get the value

# for item in info.values():

    

# get both the keys and value

for k,v in info. items():

    print(k,v)

    

v = dict.clear()

v = dict.copy()

 

# creat a dict base on the sequence and set value

v = dict.fromkeys(["k1",123,"888"],123)

print(v)

 

# get the value more safely

v = info.get("k1",11111)

print(v)

 

# pop :delete and can print the certain character

info.pop("k1")

v = info.pop("k1")

print(v)

print(info)

 

# popitem(): delete randomly and no parameter in the bracket

k,v = info.popitem()

print(info,k,v)

 

# setdefault: set default 1:if the setting key has exist ,return the value existed 2: if not exist ,creat and return the setting value

# v = info.setdefault("k1",4556)

v = info.setdefault("k3",4556)

print(info,v)

"""

# update : two ways

# info.update({"k1":3456,"k6":"good"})

info.update(k1=3456,k6="good")

print(info)

 

#***********Four frequently used*********

# keys() values() items() get() update()

 

********************************Summary*******************************

############# Summary ###########

 

############# One int###########

# int: int('123')

 

############# Two string###########

# string: upper/lower/split/replace/format/find/join/strip/startwith

 

temp = "I am {name},age is {age}"

# v = temp.format(name="alex",age=19)

v = temp.format(**{"name":"alex","age":19})

print(v)

 

############ Three list###########

# append/extend/insert

# index slice for

 

############ Four tuple###########

# ignore

# index slice for.  first stage parameter can't be changed

 

############ Five dict###########

# get/update/keys/values/items/

# for index

 

dic = {

       "k1":'v1',

       "k2":'v2'

       }

# v = "k1" in dic

v = 'v1' in dic.values()

print(v)

 

############ Six booleans###########

# 0 1

# bool(...)

# None "" () [] 0 ==>> False