First, Python, like Java, is an open-source, cross-platform language. C # is not open-source and can only run on Windows.
1. Compilation
Python is an interpreted scripting language,Source codeThe Python bytecode interpreter can directly run without compilation.CodeAnd execute related commands. Python source code file. py can be run directly, if python is installed locally. C # needs to be compiled into Il, which is managed by CLR during runtime.
2. Data Type
Python has fewer data types, only five basic numeric types, and three sequence types: String, tuples, and list. Ing type: dictionary. C # has many built-in data types. Python does not have the double type. Python does not have the char or byte type to store a single character or an 8-bit integer. Python has a built-in complex numeric type, which does not exist in C.
3. Object-oriented
In python, code (fields and functions) can be placed directly under the. py file rather than in classes. C # does not allow this.
4. Code Block
Python indent, C # Is the braces.
5. Switch
Python does not
6. For/foreach
Python does not have foreach. Python's for loop is similar to C #'s foreach. To implement the C # For Loop function, Python must use the range () function.
7. List parsing/Slicing
C # does not have this function.
8. Auto-increment/auto-increment operations
Python does not support
9. Variable Declaration
Python does not need to explicitly declare variables and is automatically declared when values are assigned. Python also does not need variable type declaration because it is a dynamic type and the interpreter judges the type. C # declare and specify the type before assigning values.
10. built-in functions
Some built-in functions of python can be called directly without passing through classes.
11. String
Python has three types of string symbols: '"''', which is flexible and C # Only has".
12. Errors and exceptions
In python, the try statement has an else clause, and C # does not.
13. Functions
The return values of Python functions are quite flexible. Different data types can be returned Based on judgment conditions, or multiple data types can be returned in the form of a single tuple. Python functions do not define the return value type.
Python functions can be passed in as parameters, while C # requires delegation to implement similar functions.
You can add attributes to Python functions at any time.
14. Embedded Functions
In python, a function can still be defined as an internal/Embedded function.
15. variable parameters of the Function
Variable parameters in Python are flexible. They can be variable-length parameters with non-keywords or variable parameters with keywords (dictionaries. C # only supports variable length parameters with non-keywords, and all variable parameters of C # must be of the same type.
16. modules and files
A file in python is considered as an independent module, and a module can also be considered as a file. The module File Name is the module name plus the extension. py. Different from other languages that can import classes, you can import module or module attributes in Python. C # is similar to the module function. A namespace can exist in multiple files or even DLL files. After importing a namespace, classes in the namespace can be directly used.
17. Load Reference Mechanism
Because the Python code is not compiled, it is more suitable to access other Python code by setting the search path. C # accesses other resources by adding references.ProgramCentralized code.
18. Inheritance Mechanism
Python supports multi-inheritance, reflecting the characteristics of object-oriented synthesis. C # does not support multi-inheritance.
19. Abstraction
Python does not support pure virtual functions or abstract methods. C # supports interfaces and abstract methods.