The road to python, Day2-python module first understanding & data types

1. Introduction to the module

First, the filename cannot be the same as the imported module name. Because the system looks for the module name from the current file by default, if the file name is the same as the imported module name, it is equivalent to calling itself, and the corresponding method will not be found.

sys module

sys.path # print environment variables

sys.argv # Implements passing arguments to the program from outside the program.

os module

os.system('dir') # Execute system commands without saving the results

cmd_res = os.popen('dir').read() # The result can be read

os.mkdir('new_dir') # create a directory

Second, the data type

1. Numbers

int (integer)

  On a 32-bit machine, the number of integers 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 integers is 64 bits. The value range is -2**63~2**63-1, that is -9223372036854775808~9223372036854775807
long (long integer)
  is different from the C language, Python's long integer does not specify the bit width, that is: Python does not limit the size of the long integer value, but in fact, due to limited machine memory, the long integer value we use cannot be infinitely large.
  Note that since Python 2.2, if an integer overflow occurs, Python will automatically convert integer data to long integers, so now not adding the letter L after the long integer data will not cause serious consequences.
float
       Literacy first http://www.cnblogs.com/alex3714/articles/5895848.html 
  Floating point numbers are used to deal with real numbers, that is, numbers with decimals. Similar to the double type in C language, it occupies 8 bytes (64 bits), of which 52 bits represent the base, 11 bits represent the exponent, and the remaining one represents the sign.
complex (complex number)
  A complex number consists of a real part and an imaginary part. The general form is x+yj, where x is the real part of the complex number and y is the imaginary part of the complex number, where x and y are real numbers.
Note: There is a small number pool in Python: -5 to 257
2. Boolean value
  Real or fake
  1 or 0

3. Index:

  The left starts from 0, and the end is -1
4. list: (there can be different data types in the list)
  append: append
  Insert: insert (index, element)
  delete: pop (index)
  replace: assignment
  Sort: sort()
  reverse order :reverse

Note: the difference between copy and copy.deepcopy (deep copy)

5、tuple:

  tuple (elements are immutable)

6、dict:

  key--value

7. String:
  The left side starts from 0, the right side starts from -1

Replenish:

* matches the preceding subexpression any number of times. For example, zo* matches "z", as well as "zo" and "zoo". * Equivalent to o{0,}
+ match the preceding subexpression one or more times (greater than or equal to 1). For example, "zo+" matches "zo" and "zoo", but not "z". + is equivalent to {1,}.
? Matches the preceding subexpression zero or one time. For example, "do(es)?" can match "do" or "do" in "does". ? is equivalent to {0,1}.

 

 

Guess you like

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