Python self-study day-Two day (1)-python environment variables, module first Knowledge and character type, python-python

Source: Internet
Author: User

Python self-study day-Two day (1)-python environment variables, module first Knowledge and character type, python-python

(1) Module
Standard module, third-party module
Initial module: sys \ OS
Standard inventory path C: \ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python35 \ Lib
Third-party reference installation inventory path: C: \ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python35 \ Lib \ site-packages

Module reference example:

Import sysimport osprint (sys. path) # print the environment variable path print (sys. argv) # print the relative path OS of the current script. system ("dir") # print the output, but do not save the result. Only the execution success or failure value is returned. _ memory = OS. popen ("dir") print (_ memory) # print the output memory address print (_ memory. read () # print the directory list OS. mkdir ("new_dir") # create a directory OS. rmdir ("new_dir") # delete a directory

Pyc c (compile) compilation, (pre-compiled bytecode file) after the custom module is referenced, A pyc file will be generated (compilation result) the next reference will first read the file ending with pyc and load it directly to avoid repeated compilation.

Python character type
Type () view Character Types
1. Number
Int integer
Long integer (no long integer type after Python3)
Float
Complex Number of complex
2. Boolean Value
True and false
1 and 0
3. String
String
4. bytes byte type
Mutual conversion between strings and binary bytes
String. encode (encoding = "UTF-8") string to binary bytes
Bytes. decode (encoding = "UTF-8") binary conversion to a string

# String-byte conversion str = "I love you, you can not love me" print ('--------', str. encode (encoding = "UTF-8 ")) byt = B '\ xe6 \ x88 \ x91 \ xe7 \ x88 \ xb1 \ xe4 \ xbd \ xa0 \ xef \ xbc \ x8c \ xe4 \ xbd \ xa0 \ xe5 \ x8f \ xaf \ xe4 \ xbb \ xa5 \ xe4 \ xb8 \ x8d \ xe7 \ x88 \ xb1 \ xe6 \ x88 \ x91 'print ('------', byt. decode (encoding = "UTF-8 "))

 



Ternary Computation
Result = a1 if condition else a2

 

Related Article

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.