python small note -2

List

list.append ( 'XXX') - is added to the list of elements

list.extend ([ 'xx', 'yy']) - appended to the list of the plurality of elements

list .insert (1, 'xxx') - the element is inserted into the specified position

  • The x, y, z values ​​of the three variables swap

x , y , z = z ,y ,x

  • Membership operator

in - for checking whether a value in the sequence

type () / isinstance () - Analyzing variable type

Example:

member =['a' , 'b' , 'c ']

  • del member [1] - delete the second element

          member.remove('a') 

          member.pop (1) - (the second member is removed from the element, the element is taken out is no longer in the list)

          # Name = member.pop (1) is a

  • member [0: 3] - the first three elements of the list to obtain
  • member2 = member [:] - fragmentation Copy - copy and member2 = distinguished member - which member2 member will vary with changes
  • List comprehensions - create a list dynamically

例: list 1 =[ i*i for i in range (10) ]  —— list 1 = [ 0,1,4,9,16,25,36,49,64,81]

Is equivalent to: list 1 = []

              for i in range (10):

                   list 1. append(i*i)

  • list.sort () - ascending order --list.sort (reverse = True) - in descending order
  • list.reverse () - list in reverse order
  • list2 = list1.copy () - Copy list1
  • list.clear () - clear the list of elements, list2 becomes empty list
  • list.count ( 'xxx') - an element number appears in the list
  • list.index ( 'xxx', 2, 7) - position of the search elements in the list; 2,7 starting and ending positions, i.e., range

Tuple

the tuple "," is the key

  • temp1 = (1,) # only one tuple element, without parentheses
  • temp2 = 2,3,4 # tuple with three elements
  • 8*(8)——>64
  • * 8 (8) -> (8,8,8,8,8,8,8,8) # "*" to repeat the operator
  • All objects, comma separated, with no clear definition of the default set of symbols is a tuple type

x , y , z =1 , 2 , 3

type (x) =<class 'int'>

h= x , y , z

type (h)=<class 'tuple'>

Tuples and strings of changes, update

例:tuple1 [:6]+("xxx"  ,  )  + tuple2 [6:]

       str1 [:6] + 'xxx' + str1 [6:]

String

String methods and notes

https://fishc.com.cn/forum.php?mod=viewthread&tid=38992&extra=page%3D1%26filter%3Dtypeid%26typeid%3D403

Symbol Meaning format string and escape character meaning

https://fishc.com.cn/forum.php?mod=viewthread&tid=92997&extra=page%3D1%26filter%3Dtypeid%26typeid%3D403

s is a string

s.isalnum () All characters are numbers or letters, is true returns Ture, otherwise False.

s.isalpha () All characters are letters, is true returns Ture, otherwise False.

s.isdigit () All characters are numeric, true return Ture, otherwise False.

s.islower () are all lowercase characters, true return Ture, otherwise False.

s.isupper () All characters are uppercase, true return Ture, otherwise False.

s.istitle () all words are capitalized, is true returns Ture, otherwise False.

s.isspace () all characters are blank characters, true return Ture, otherwise False.

  • Sequence - a listing of some BIF, tuples, strings

max() 

(I)

sum () - sum (list1, 8) - the number of elements in list1 added together before adding 8

sorted () - in ascending order

list(reversed(numbers))

list (enumerate (numbers)) - generation of the index value of each element and the value of the item consisting tuple

list (zip (a, b)) - Returns a, b where the parameters a tuple

 

Guess you like

Origin www.cnblogs.com/Aurakkk-8/p/11620374.html