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:
- Programs written in Python (.py files)
- C or C++ extensions (compiled as shared libraries or DLL files)
- Package (containing multiple modules)
- 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?
- Use multi – process, make full use of machine multi – core performance
- Parts of the code that have a significant performance impact can be written in C or C++
- The performance impact of I/O blocking can be addressed using I/O multiplexing
- Use Python’s built-in functions whenever possible
- Use local variables whenever possible
Question 5: Scope in Python?
Shorthand for LEGB
- Local scope (Local)
- Enclosing locals is the local scope where the current scope is embedded.
- Global/module scope (Global)
- Built-in scope.
Question 6: How to understand strings in Python\
Characters?
- Escape the character \n \t
- The pathname is used to connect the pathname c:\ ABC \def
- Writing too long code manually
Soft 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