In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the difference between Python and other languages". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. What is the difference between Python and other languages?
Python is an interpretive programming language with concise and beautiful syntax, powerful functions, a wide range of applications, and a strong type of dynamic, portable, extensible and embedded third-party library.
The difference between strongly typed and weakly typed languages:
If a language often implicitly converts the types of variables, then the language is weakly typed, and if it rarely does so, it is strongly typed. Python rarely implicitly converts the types of variables, so Python is a strongly typed language.
The fundamental judgment of strongly typed language and weakly typed language is whether the language type conversion will be implicitly carried out. The speed of strongly typed reasons may be slightly lower than that of weakly typed languages, but the rigor of strongly typed definitions avoids unnecessary errors.
Strongly typed languages include: Java,. Net, Python, C++ and other languages. Python is a dynamic language, a strongly typed language, a type-safe language, Java is a static language, a strongly typed language, and a type-safe language; weakly typed languages include: VB,PHP,JavaScript and other languages. VBScript is a dynamic language, which is a reason for type unsafety. The difference between dynamic language and static language:
Dynamically typed language: a dynamically typed language is a language that does data type checking only at run time, that is, when a dynamically typed language is programmed, it never has to assign a data type to any variable, and the language will record the data type internally when it is assigned to a variable for the first time. Python and Ruby are typical dynamically typed languages, while other scripting languages such as VBScript are more or less dynamically typed.
Statically typed languages: statically typed languages are just the opposite of dynamically typed classes, whose data types are checked during compilation, that is to say, you have to declare the data types of all variables when you write the program. Cmax Cure + is a typical representative of statically typed languages, and other statically typed languages include C #, Java, and so on.
The fundamental distinction between dynamic and static languages lies in whether the data type is checked at run time or at compile time. The difference between compiled language and interpreted language:
Compiled language: a program needs to be translated directly into machine code (for a non-cross-platform language such as C _ Java) or intermediate code (a cross-platform language like Java, which requires a virtual machine to print the intermediate code into machine code). Generally need to go through the compilation (compile), link (linker) these two steps. Compilation is to compile the source code into machine code, and linking is to concatenate the machine code of each module with the dependent library to generate an executable file.
Interpretive language: use the interpreter to interpret the source code line by line into machine code and execute it immediately, without overall compilation and linking processing, which saves a lot of work compared to the compiled language.
One is like eating and other dishes are all served before starting, the other is like eating hot pot, rinsing while eating, the time is different.
The advantages of interpretive language: cross-platform is easy, only need to provide a platform-specific interpreter; disadvantages: it has to be explained every time it is run, and its performance is inferior to that of compiled language. 2. Briefly describe the interpretive and compiled programming languages?
3. What are the interpreter types and related features of Python?
CPython: official version of the interpreter. This interpreter is developed in C language, so it is called CPython. Running python from the command line starts the CPython interpreter. CPython is the most widely used Python interpreter.
IPython:IPython is an interactive interpreter based on CPython, that is, IPython is only enhanced in the way it interacts, but the function of executing Python code is exactly the same as CPython. CPython uses > > as the prompt, while IPython uses In [serial number]: as the prompt.
PyPy: its goal is execution speed. PyPy uses JIT technology to dynamically compile Python code (note that it is not interpreted), so it can significantly improve the execution speed of Python code. Most Python code can be run under PyPy, but there are some differences between PyPy and CPython, which results in different results for the same Python code executed under the two interpreters.
Jython:Jython is a Python interpreter running on the Java platform, which can directly compile Python code into Java bytecode for execution.
IronPython:IronPython is similar to Jython, except that IronPython is a Python interpreter running on Microsoft's .net platform that compiles Python code directly into .net bytecode. 4. What do you know about the difference between Python3 and Python2?
Coding: the default encoding of Python2 is asscii, which is one of the reasons why coding problems are often encountered in Python2. As for why asscii is used as the default encoding, the reason is that Unicode did not appear when the language Python was born. Python3 defaults to UTF-8 as the default encoding, so you no longer need to write # coding=utf-8 at the top of the file.
String: type of character in Python2, str: byte sequence after encoding, unicode: text character before encoding, while character type in Python3, str: encoded unicode text character, bytes: byte sequence before encoding.
You can think of a string as having two states, the text state and the byte (binary) state. The two character types in Python2 and Python3 correspond to these two states respectively, and then encode and decode each other. Encoding is to convert a string into bytecode, which involves the internal representation of the string; decoding is to convert the bytecode into a string and display bits into characters.
In Python2, both str and unicode have encode and decode methods. However, it is not recommended to use encode for str and decode for unicode, which is a flaw in Python2 design. Python3 is optimized, str has only one encode method to convert a string into a bytecode, and bytes has only one decode method to convert bytecode into a text string.
Print in print:Python2 is a statement; print in Python3 is a function. For example:
# py2 > > print ("hello", "world") ('hello',' world') # py3 > print ("hello", "world") hello world
This example is obvious. In py2, the print statement is followed by a tuple object, while in py3, the print function can accept multiple positional parameters. If you want to use print as a function in Python2, you can import print_function in the future module.
Import:python2 defaults to importing modules and packages according to relative paths, while python3 defaults to importing modules and packages in absolute paths.
Input:Python3:input parsing input is str character type; Python2:input parsing input is int input, and raw_input parsing input is str type.
Operator: in Python2, / performs traditional division, performs truncated division on integers, and floating-point division (leaving decimal parts, even if divisible) for floating-point numbers; / / performs Floor division, truncates the remainder and returns an integer for integer operands, or returns a floating-point number if any Operand is a floating-point number. In Python3, / always performs true division and returns a floating-point result containing any remainder, regardless of the type of Operand; / / performs Floor division, truncates the remainder and returns an integer for integer operands, or a floating-point number if any Operand is floating-point.
In int/long:Python3, there is only one integer type, int, which in most cases is very similar to the long integer in Python2. Python2 has int and long types for non-floating point numbers. The maximum value of the int type cannot exceed sys.maxint, and this maximum value is platform-dependent.
True and False: in Python2, True and False are two global variables (names) that correspond to 1 and 0 respectively. Since they are variables, they can point to other objects. Python3 fixed this flaw by changing True and False to two keywords that always point to two fixed objects and are not allowed to be re-assigned.
Iterators: many built-in functions and methods that return list objects in Python2 are changed to return iterator-like objects in Python3, because the lazy loading nature of iterators makes it more efficient to manipulate big data.
For example: xrange () is used in Python2 to create an iterator object, and range () is used to create an list array (xrange is much better than range when generating a large sequence of numbers, because there is no need to open up a large piece of memory space in the first place); and range () is used in Python3 to create an iterator object, removing the xrange () method.
In addition, the dictionary object's dict.keys () and dict.values () methods no longer return a list, but as an iterator-like view object. Higher-order functions map, filter, and zip no longer return list objects. Python2's iterator must implement the next method, while Python3 has been changed to _ _ iter__ (), next.
Nonlocal: in Python2, you can declare a variable as a global variable with the keyword global in the function, but it is impossible to declare a variable as a non-local variable in a nested function. In Pyhon3, the keyword nonlcoal is added, which is generally used in closures to make the variable use the outer variable of the same name.
Understanding of LEGB scope: a brief Analysis of python3's local, global and nonlocal
This is the end of the content of "what's the difference between Python and other languages". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.