Question 1: Common methods of OS modules in Python?

OS belongs to the python built-in module, so the details in the website has detailed instructions, this interview problem is the basic ability, so tell the interviewer you know Website address https://docs.python.org/3/library/os.html

The OS module contains many functions for manipulating files and directories

OS object methods

The name of the function use
os.remove() Delete the file
os.walk() Generate all file names in the directory tree
os.chdir() Change the directory
os.getcwd() Returns the current working directory
os.listdir(path=”.”) Enumerates the file names in the specified directory (“.” indicates the current directory, “..” Represents the upper level directory)
os.mkdir(path) Creates a single-layer directory and throws an exception if the directory already exists
os.rename(old,new) Rename the file old to new
See official Internet cafe for more content The official website is easy to read

2. What are modules and packages in Python?

Python Module (Module)

  • In Python, modules are a way to build programs.
  • Each Python code file is a module and can reference other modules, such as objects and properties.

The written code is saved as a file. This file is a module. ABC. Py The file name ABC is the module name.

There are four code types of modules:

  1. Programs written in Python (.py files)
  2. C or C++ extensions (compiled as shared libraries or DLL files)
  3. Package (containing multiple modules)
  4. Built-in modules (written in C and linked to the Python interpreter)

Python Package (Package)

A Package is a directory that contains module files. The directory name is the Package name. A directory can contain directories and subdirectories are packages, but the Package name should contain the name of the directory at the next level.

Python introduced grouping modules by directory to avoid module name collisions, which can be the same in different packages.

Note that each package directory has an __init__.py file underneath it, which must exist otherwise Python treats the directory as a normal directory rather than a package. __init__.py can be an empty file or have Python code, because __init__.py is itself a module, and its module name is the package name.

To further understand, you can refer to

www.cnblogs.com/GhostCatcg/…

What is an interpreted language and what is a compiled language?

Computers can’t understand high-level languages directly, they can only understand machine languages directly so they have to translate high-level languages into machine languages to execute programs written in high-level languages.

  • Interpreted languages translate only when the program is running.
  • Compiled languages require a special compilation process to compile programs into machine language (executable files) before they can be executed.

4. How can I improve the performance of Python programs?

  1. Use multi – process, make full use of machine multi – core performance
  2. Parts of the code that have a significant performance impact can be written in C or C++
  3. The performance impact of I/O blocking can be addressed using I/O multiplexing
  4. Use Python’s built-in functions whenever possible
  5. Use local variables whenever possible

Question 5: Scope in Python?

Shorthand for LEGB

  1. Local scope (Local)
  2. Enclosing locals is the local scope where the current scope is embedded.
  3. Global/module scope (Global)
  4. Built-in scope.

Question 6: How to understand strings in Python\Characters?

  1. Escape the character \n \t
  2. The pathname is used to connect the pathname c:\ ABC \def
  3. Writing too long code manuallySoft line

Question 7: Why can function names be used as arguments?

In Python, everything is an object, and a function name is the memory space of the function, which is also an object.

8








Welcome to pay attention to her public number, non-undergraduate programmer