Python First Knowledge-day2

Source: Internet
Author: User

1. Module Initial knowledge

The libraries in Python include standard libraries and third-party libraries, which you can import directly when you want to use them, and import the format "Import library module", for example:

1 import sys  #sys for Python's standard library 2print(sys.path)     #  Print environment variable 3print (SYS.ARGV)     # Printing relative path

Again such as:

1 ImportOS2Cmd_res = Os.system ('dir')#Execute command only, do not save result3 Print(' -', Cmd_res)#The print result is 0, which means the operation was successful.4 5Cmd_res2 = Os.popen ('dir'). Read ()#executes the command, saves the result, without read, and prints the result as ' <os._wrap_close object at 0x0057c8f0> ' representing the address of the memory object6 Print(' -', Cmd_res2)#read out the results after adding read7 8Cmd_res3 = Os.mkdir ('New_dir')#Create a multilevel directory
View Code

2. What is a PYc file

(1) What is Python?

Python is an object-oriented, interpreted computer programming language, invented by Dutchman Guido van Rossum in 1989, and the first public release was released in 1991.

Like Java/c#, it's also a virtual machine-based language.

(2) Brief description of Python's running process

On the surface: when we enter Python hello.py on the command line, we actually activate the Python interpreter to get it to work. But before "explain", the first task it performs is compile.

Just in the Pycharm class of Ides, two processes are in one. So python, like Java, is a language that is compiled and interpreted first.

In essence: When the Python program runs, the compiled results are saved in the Pycodeobject in memory when the Python program finishes running. The Python interpreter writes the pycodeobject back to the PYc file.

When this Python program runs for the second time, it will first look for the PYc file on the hard disk, if it is found, then load it directly, otherwise repeat the process, so we can say that the PYc file is the persistent storage method of Pycodeobject.

3. Data type description

<1> Digital

(1) Int (integral type)

On a 32-bit machine, the integer number is 32 bits, the value range is -2**31~2**31-1, and the same is true on 64-bit machines with 64 bits and a range of -2**63~2**63-1.

(2) long (L-integer)

Unlike the C language, Python's long integers do not refer to the positioning width, that is, Python does not limit the size of long integer values, but machine memory is limited and cannot be infinitely large.

It is worth noting that after Python2.2, integer overflow, python will automatically convert integers to long integers, so now long integers without l will not go wrong.

(3) Float (float type)

A floating-point number is a real number, similar to the double type in C, which occupies 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one is a symbol.

(4) complex (plural)

The complex number is composed of real and imaginary parts, the general form is x+yj,x for real numbers, and y is the imaginary number.

<2> Boolean values

True (True) or False (false)

1 or 0

<3> string

For example: "Hello world!"

string concatenation, "+" each time it appears, it will re-open a space in memory.

<4>bytes type

In Python 3, the text and binary data are clearly distinguished, the text is always Unicode, denoted by the STR type, and binary data (such as video, picture, etc.) is represented by the bytes type.

1msg ="Our goal is the star of the Sea"2 Print(Msg.encode (encoding='Utf-8'))#encode is encoded and encodes the string into binary data (must be transferred at the time of transfer)3 #The output is: B ' \xe6\x88\x91\xe4\xbb\xac\xe7\x9a\x84\xe7\x9b\xae\xe6\xa0\x87\xe6\x98\xaf\xe6\x98\x9f\xe8\xbe\xb0\ Xe5\xa4\xa7\xe6\xb5\xb7 '4 5 Print(Msg.encode (encoding='Utf-8'). Decode (encoding='Utf-8'))#Decode is decoding, decoding binary data into strings, etc.6 #the output is: Our goal is the star of the Sea
View Code

4. Ternary operation

result = value 1 if condition else value 2 (if the condition after if is true, result = value 1, otherwise result = value 2).

1 A = 12 b = 23 c = 34if a > B  else#result = value 1 If condition else value 25print(d)6# If the condition is true, d = A; if the condition is false, d = C. 

5. Binary

Binary: 0 1

Octal: 0 1 2 3 4 5 6 7

Hex: 0 1 2 3 4 5 6 7 8 9 A B C D E F

Binary and hexadecimal conversions refer to https://jingyan.baidu.com/article/47a29f24292608c0142399cb.html

    

Python First Knowledge-day2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.