Standard data types (6 types)

  1. Address immutableAs long as these three values are the same, they must have the same ID
  • The Number is subdivided into:Int, float, bool, complex
  • String (String)
  • Tuple (Tuple)
  1. Address of a variable
  • List (List)
  • Set
  • The Dictionary

Determine type

  1. typeOutput data type, usage: type (a)
  2. isinstanceUse: isinstance (a, int)

Difference: Type does not consider a subclass to be a parent type. Isinstance considers a subclass to be a superclass type

In Python3, bool is a subclass of int. True and False can be added to numbers. True==1 and False==0 return True, but is is used to determine the type.

== is different from is

  • Is is used to determine whether two variable reference objects are the same, and == is used to determine whether the values of reference variables are the same.

Data type conversion

Commonly used functions

The join: string` list `turn'string'  The '-'.join(list)
split:'string'turn` list `    str.split('w')
/ / list
`append`Appends the list element list.append(1)
`extend`Extend: appends multiple elements to a list. The argument is list.extend([1.2])
`insert`Insert an element in the middle of the list.1[1.2])
`pop`The last element of the list is deleted by default. The first parameter can be specified to delete the index list.pop(1)
`remove`: Removes the first match of a value in the list. List.remove ('yellow')
`reverse`List.reverse () : elements in the reverse list`sort`Reverse = True descending, reverse = False ascending (default) list.sort(reverse = True)`copy`Copy () copy a new list and reallocate the new memory.`clear`: Clears the list. Compared to list=[], clear does not reallocate new memory`tuple`: List tuple`list`: Tuple transfer listCopy the code

Logical operator

And the first one is true output the second one or the first one is true output the first one

String formatting

1.print ("My name is % S and I am % D!" % ('Ming'.10))

2.name='xiaoming'   / / f - string (python3.6 +)
  f'Hello {name}'  

3.x=1    In Python 3.8, you can use the = symbol to concatenate an expression and a result
  print(f'{x+1=}')  //x+1=2
Copy the code