A simple comparison of Python and C (Python3.0)

Source: Internet
Author: User

Python is one of the hottest languages of all time, and the rise of AI has made Python a household name all night, and Python is now the easiest language to learn, and many colleges and universities have begun to use Python as the starting language for freshmen. Ben Meng is also just beginning to contact Python, found that Python and other languages is really a big difference. Python is implemented in C, so I want to make a simple comparison between Python and C.

1.C language is a compiled language, after compiling, generate machine code, and then run, execute fast, not cross-platform, generally used for operating system, driver and other bottom-level development.

Whether Python is a compiled or interpreted type is not obvious, but is generally understood as an interpreted language, slow to execute, Python is cross-platform due to Python virtual machines, and Python is highly integrated for rapid software development.

Data types for 2.C languages such as:

C language needs to define the variable type in advance, in the case of the int type, when an int variable is defined, it will open 4 bytes in memory, then initialize, because the length is specified, in the process of operation need to consider, overflow, accuracy and so on.

Data types in Python:

1.Number: Digital

Int

Float

Bool

Complex

2.String: String

3.List: List

4.Tupel: Tuples

5.Sets: Collection

6.Dictionary: Dictionary

Python does not need to define the variable type beforehand, taking a=3 as an example, storing an integer 3 in memory, and then using the variable A to point to 3, the variable A is of no type, and the type we call refers to the type of the object in memory that the variable refers to.

Python's friendliness can be seen from the data type, with fewer basic data types, no annoying pointers, no data overflow and accuracy issues, and when you need to use a variable in your program, you can use it directly without having to define the variable at the beginning of the program. In addition to this, Python also provides str,list,dict these powerful data types, making program development easier.

3.Python also provides an interactive interface, input python into the interactive interface, enter exit () exit interface, similar to the Linux terminal, enter a line of command, the execution of a line, to learn Python provides a great convenience.

4. There is no big difference between the operators and the precedence, but there is no self-add and subtract operators in Python, and Python differs from the C language on logical operators, Python is And,or,not, and C is &&,| |,!

In 5.Python, the statement body is represented by indentation, and the C language uses {} to represent the body of the statement, and there is no semicolon after the end of each statement in Python, the statement if else, which is no different, the loop statement while is not, just for loop, python through for In to indicate

6.Python has a lot of built-in functions (build in function), no need to write headers, Python has a lot of powerful modules, you can import it when you need it. C language At this point is far less than Python, most of the time you need to manually implement.

7.C language functions, with strict order restrictions, if you want to call a function, the function needs to be implemented before the call, or at the beginning of the program declaration, and Python there is no such restriction, Python also has 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 function in memory, which greatly reduces the length of the code.

8.C language is a process-oriented language, and many times it is necessary to implement a function manually to complete a function. The introduction of classes and objects in Python is a language of object-oriented programming, and object-oriented makes the reusability of code much better, and the encapsulation of data.

Summary: Python can be said to be a very ' simple ' language, highly integrated, with a small amount of code, and simply relative to other languages. Programming is never a simple job, we need to learn constantly, master the underlying principle of implementation, is the right path.

A simple comparison of Python and C (Python3.0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.