Which is more worth learning, Python or C language? Is there a big difference between C language and Python?

Hello everyone, the editor will answer your question about which language is more worth learning, Python or C. Many people still don’t know the big difference between c language and python. Let’s take a look together now!

Python can be said to be one of the hottest languages ​​at present. The rise of artificial intelligence has made Python a household name overnight. Python is known as the easiest and easiest language to learn. Now many colleges and universities have begun to use Python as an introduction to freshmen. language. I have just started to come into contact with Python and found that there is a big difference between Python and other languages. What foundation is needed to learn python ? Python is implemented in C language, so I would like to make a simple comparison between Python and C language.

1. Language type

Python is an interpreter-based language, and the interpreter reads the code line by line; Python is first compiled into bytecode, which is then interpreted by a large C program.

C is a compiled language, and the complete source code will be directly compiled into machine code and executed directly by the CPU.

2. Memory management

Python uses an automatic garbage collector for memory management.

In C language, programmers have to do memory management themselves.

3. Application

Python is a general-purpose programming language, a multi-paradigm. It mainly supports object-oriented programming, procedural programming, and functional programming.

C is a structured programming language. Functions, selections (if/else etc.), iteration (loops) are allowed. It is mainly used for hardware related applications.

4. Speed

Due to historical reasons, the Python programming language has a GIL lock, which results in insufficient multi-threading support and slow running speed; while C language is very fast, C language is a relatively low-level language, and its running efficiency is better than Python.

5. Different complexity

In Python, there is no need to declare variable types. In C, variable types must be declared.

Python programs are easier to learn, write and read. And C program syntax is more difficult than Python.

Testing and debugging is easier in Python; testing and debugging in C is harder.

Knowledge point expansion

Big difference. Python is implemented in C language, so I would like to make a simple comparison between Python and C language.

1. C language is a compiled language. After compilation, it generates machine code and then runs it. It has fast execution speed and cannot be cross-platform. It is generally used for low-level development such as operating systems and drivers.

The boundary between whether Python is compiled or interpreted is not obvious, but it can generally be understood as an interpreted language with slow execution speed. Due to the Python virtual machine, Python can be cross-platform. Python's high degree of integration is suitable for rapid software development.

two,

20190707075259.png

In C language, variable types need to be defined in advance. Taking the int type as an example, when an int type variable is defined, 4 bytes will be opened in the memory and then initialized. Since the length is specified, it needs to be considered during the operation process. , overflow, accuracy and other issues.

Data types in Python:

1.Number: number

Int

Float

Bool

Complex

2.String: string

3.List: list

4.Tupel: tuple

5.Sets: collection

6.Dictionary: Dictionary

Python does not need to define the variable type in advance. Taking a=3 as an example, store an integer 3 in the memory, and then use the variable a to point to 3. The variable a has no type. The type we refer to refers to the memory pointed by the variable. The type of object in .

The friendliness of Python can be seen from the data type. There are fewer basic data types, there are no annoying pointers, and there is no need to consider data overflow and precision issues. When a variable needs to be used in the program, it can be used directly. , without defining the variables at the beginning of the program. In addition, Python also provides powerful data types such as str, list, and dict, making program development easier.

3. Python also provides an interactive interface. Enter python to enter the interactive interface, and enter exit() to exit the interactive interface. It is similar to a Linux terminal. Enter a line of commands and execute a line, which provides great convenience for learning Python.

4. In terms of operators and priorities, there is no big difference between the two, but there are no self-increment and self-decrement operators in Python. Python is also different from C language in terms of logical operators. In Python, they are and, or, not, and in C language it is &&, ||,!

6. In Python, indentation is used to represent the statement body, and C language uses {} to represent the statement body, and there is no semicolon after the end of each statement in Python. There is no difference between the judgment statement if else and the loop statement while. , just a for loop, Python expresses it through for in.

7. Python has many built-in functions (build in function), so there is no need to write header files. Python also has many powerful modules that can be imported when needed. C language is far inferior to Python in this regard, and most of the time you need to implement it manually.

8. Functions in C language have strict order restrictions. If you want to call a function, the function needs to be implemented before this call, or declared in advance at the beginning of the program. However, there is no such restriction in Python. There are also There is the concept of higher-order functions, that is, the function name can also be used as a function parameter. The function name is also a variable that points to a certain function in the memory. This way of writing can greatly reduce the length of the code.

Python also provides variable parameters and keyword parameters, which greatly improves the function of the function. It used to be necessary to write multiple functions, but now only one function is needed to achieve these functions.

9. C language is a process-oriented language. Many times, you need to manually implement functions to complete a certain function. Classes and objects are introduced in Python, which is an object-oriented programming language. Object-oriented greatly improves the reusability of code and better encapsulation of data. I won’t go into details about the specific comparison between object-oriented and process-oriented, but there are two very important words: classes are abstract, while objects are concrete.

10. There are both functions and methods in Python, which often makes people confused. I personally feel that it is not necessary to make a clear distinction, but there is still a big difference between the two: functions are free, while methods are restricted. When programming, you need to distinguish whether you are calling a method or a function.

Summary: Python can be said to be a very 'simple' language, highly integrated, with a small amount of code. It is simple compared to other languages. But programming is never a simple job. We need to continue to learn and master the underlying implementation principles, which is the right way.

Guess you like

Origin blog.csdn.net/chatgpt001/article/details/132968844