A Preliminary Study of Python Part 1 - Variables and Basic Data Types

variable

  The variables in Python are different from those in the C language. Python is a dynamically typed language, so there is no need to declare the type of the variable in advance. The type and value of the variable are initialized together at the moment of assignment. Each variable must be assigned a value before it is used, and the variable will not be created until the variable is assigned.

  And the assignment statement in Python is to establish the reference value of the object, not the object, just like the pointer, not the area where the data is stored.

test_list=[1,2,3,4]
new_list = test_list       #Not a copy of test_list, just a reference to 
test_list new_list.append(5 )
 print (test_list)            # [1,2,3,4,5]

Therefore, the issues of deep copy and shallow copy will be involved, which will not be elaborated here, and will be discussed later.

basic data type

1. Numbers

int (integer)

  On a 32-bit machine, the number of digits of an integer is 32 bits, and the value range is -2**31 to 2**31-1, that is, -2147483648 to 2147483647 On a 64-bit system, the number of digits of an integer is 64 bits. The value range is -2**63~2**63-1, that is -9223372036854775808~9223372036854775807

2. Boolean value (bool)

 

3. String

 

new_str="Hello,world"

 

String common functions: 

  • remove blank strip()
  • split split()
  • length len()
  • index new_str[0]
  • slice new_str[1:3]
4. List
 
Create a list:
name_list=[]
name_list=list([])

Basic operation:

  • index
  • slice
  • Add append ()
  • remove pop() remove()
  • lengthlen()
5. Tuple
 
Create a tuple:
new_tuple=(1,2,3)

Tuple contents are not modifiable

Basic operation:
  • index
  • slice
  • traverse
  • length
  • Include

 

6. Dictionary (unordered)
 
Create a dictionary:
new_dic={key1:value1,
         Key2:value2}        

Common operations:

  • index
  • new
  • delete
  • key, value, key-value pair
  • traverse(key\value\key-value pair)
  • length

 

operator  

1. Arithmetic operation:

2. Comparison operation:

3. Assignment operation:

4. Logical operation:

5. Member operation:

 

operator  

1. Arithmetic operation:

2. Comparison operation:

3. Assignment operation:

4. Logical operation:

5. Member operation:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325111081&siteId=291194637