The difference between the C language and python

Python is arguably one of the hottest of the language, and the rise of artificial intelligence to make Python become a household name overnight, Python is currently known as the most easy to learn the language, there are many colleges and universities will begin Python as a freshman entry language. This new Meng also just getting started with Python, Python and other languages ​​found There is a big difference. Python is implemented in C, Python and C language and therefore wanted to make a simple comparison.

One,

C language is compiled language, compiled after generating machine code, and then run, execution speed can not be cross-platform, generally used for the development of the underlying operating system, drivers and the like.

Python is compiled or interpreted this limit is not obvious, but generally can be understood as an interpreted language, performs slowly, due to the Python virtual machine, Python is cross-platform, Python highly integrated software suitable for rapid development.

two,

Data type of C language as shown below:

 

C language variable type has to be defined as an int for example, when the definition of a variable of type int, 4 bytes would be opened in the memory is initialized again, since the length is specified, to be considered in the calculation process overflow, accuracy and other issues.

Python Data Type:

1.Number: Digital

  Int

  Float

  Bool

  Complex

2.String: String

3.List: List

4.Tupel: tuple

5.Sets: collection

6.Dictionary: Dictionary

ython not necessary to previously defined variable type to a = 3, for example, an integer stored in the memory 3, and then use a variable point 3, is not a type of variable, we refer to the type of said memory variable referred types of objects.

From the data types Python-friendliness can be seen, substantially fewer types of data, the pointer is not annoying, and does not need to consider the accuracy of the data overflow, required when a variable in the program, can be used directly without the need to define variables at the beginning of the program. In addition, Python also offers str, list, dict these powerful data type allows an application developer becomes easier.

three,

Python also provides an interactive interface, type python into the interface, enter exit () to exit the interface, similar to the Linux terminal, enter a command line, one line for learning Python provides a great convenience.

four,

In the operator priority and above, and both no big difference, but no self-imposed and decrement operators in python, logical operators in C language and different from the Python, Python is and, or, not, the C language is &&, || ,!

six,

Python statement represented by body indentation, C language statements represented by {} body, and after the end of each Python no semicolon statement, the statement is determined if else, no difference between the two, while there is no loop, but for circulation, Python is represented by for in.

Seven,

Python has a lot of built-in functions (build in function), no need to write the header file, there are many powerful Python modules can be imported if needed. C language at this point far less than Python, most of the time required to manually achieve.

Eight,

C language function, has a strict limit order, if you want to call the function, which will need to be implemented before this call, or prior statement at the beginning of the program, while in Python is not the limit, as well as high in Python order functions is the concept that the function name can also be used as function parameters, function name is also a variable that points to a function in memory, such an approach can greatly reduce code size.

python also provides variable parameters and keyword parameters, so that the performance function greatly improved, the original need to write multiple functions, now only need a function that can perform these functions.

nine,

C language is a process-oriented language, often need to manually implement functions to complete certain functions. Python introduced classes and objects, object-oriented programming language, the reusability of the object-oriented code such greatly improved, and better data encapsulation. Object-oriented and process-oriented specific comparison is not to say, but there are two very important words: class is abstract, and the object is concrete.

ten,

python in both functions, there are ways, often people wonder, I personally feel there is no need to distinguish very clearly, but there are two big differences: function is free, but the method is limited . When programming is required to distinguish the method or function call.

 

Summary : Python can be very simple `` language, highly integrated, less code, is relatively simple in terms of other languages. But programming is never a simple living, we need to continue to learn and master the underlying implementation principle, is the right way.

Python is arguably one of the hottest of the language, and the rise of artificial intelligence to make Python become a household name overnight, Python is currently known as the most easy to learn the language, there are many colleges and universities will begin Python as a freshman entry language. This new Meng also just getting started with Python, Python and other languages ​​found There is a big difference. Python is implemented in C, Python and C language and therefore wanted to make a simple comparison.

One,

C language is compiled language, compiled after generating machine code, and then run, execution speed can not be cross-platform, generally used for the development of the underlying operating system, drivers and the like.

Python is compiled or interpreted this limit is not obvious, but generally can be understood as an interpreted language, performs slowly, due to the Python virtual machine, Python is cross-platform, Python highly integrated software suitable for rapid development.

two,

Data type of C language as shown below:

 

C language variable type has to be defined as an int for example, when the definition of a variable of type int, 4 bytes would be opened in the memory is initialized again, since the length is specified, to be considered in the calculation process overflow, accuracy and other issues.

Python Data Type:

1.Number: Digital

  Int

  Float

  Bool

  Complex

2.String: String

3.List: List

4.Tupel: tuple

5.Sets: collection

6.Dictionary: Dictionary

ython not necessary to previously defined variable type to a = 3, for example, an integer stored in the memory 3, and then use a variable point 3, is not a type of variable, we refer to the type of said memory variable referred types of objects.

From the data types Python-friendliness can be seen, substantially fewer types of data, the pointer is not annoying, and does not need to consider the accuracy of the data overflow, required when a variable in the program, can be used directly without the need to define variables at the beginning of the program. In addition, Python also offers str, list, dict these powerful data type allows an application developer becomes easier.

three,

Python还提供了一个交互界面,输入python进入交互界面,输入exit()退出交互界面,类似于Linux终端,输入一行命令,执行一行,为学习Python提供了很大的便利。

四、

在运算符和优先级上面,两者并没有大的区别,但在python中没有自加和自减运算符,在逻辑运算符上Python也区别于C语言,Python中是and,or,not ,而C语言中则是&&,||,!

六、

Python中通过缩进来表示语句体,C语言通过{}来表示语句体,并且在Python中每一条语句结尾后没有分号,判断语句if else,这两者没有区别,循环语句while也没有,只是for循环,Python通过for  in来表示。

七、

Python有很多内置函数(build in function),不需要写头文件,Python还有很多强大的模块,需要时导入便可。C语言在这一点上远不及Python,大多时候都需要自己手动实现。

八、

C语言中的函数,有着严格的顺序限制,如果要调用函数,该函数需要在本次调用之前就需要被实现,或者在程序开头事先声明,而Python中则没有这个限制,Python中还有高阶函数这一概念,即函数名也可当作函数参数,函数名也是一种变量,指向内存中的某个函数,这种写法可以大大减少代码长度。

python中还提供了可变参数和关键字参数,这样使得函数的功能大大提高,原来需要写多个函数,现在只需要一个函数就可以实现这些功能。

九、

C语言是面向过程的语言,很多时候都需要自己手动实现函数来完成某一功能。Python中引入了类和对象,是面向对象编程的语言,面向对象使得代码的可重用性大大提高,数据的封装性也更好。面向对象与面向过程的具体比较就不多说了,但有两句非常重要的话:类是抽象的,而对象是具体的。

十、

python中既有函数也有方法,常常让人疑惑,我个人觉得也没有必要区分的非常清楚,但是两者还是有较大的区别:函数是自由的,而方法是受限的。在编程的时候需要分清楚调用的是方法还是函数。

 

总结:Python可以说是非常`简单`的语言,高度集成,代码量少,简单是相对其他语言而言。但编程从来都不是一个简单活,需要我们不断学习,掌握底层实现原理,才是正道。

Guess you like

Origin www.cnblogs.com/abdm-989/p/11959036.html