Home  >  Article  >  Backend Development  >  The difference between c language and python

The difference between c language and python

藏色散人
藏色散人Original
2019-07-03 09:37:159044browse

The difference between c language and python

The difference between c language and python

1. Different language types.

Python is a dynamically typed language and a strongly typed language. They determine the type of a variable the first time you assign a value to it. C is a statically typed language, a language in which data types are determined at compile time. Most statically typed languages ​​ensure this by requiring that the data type of any variable be declared before its use.

2. The object mechanism is different.

All data in Python are represented by objects or relationships between objects. Functions are objects, strings are objects, and everything is the concept of an object. Every object has three properties: entity, type and value.

There is no concept of object in C, only "data representation". For example, if there are two int variables a and b, and you want to compare the sizes, you can use a == b to judge, but if there are two int variables a and b, you can use a == b to judge. string variables a and b, you have to use strcmp to compare, because at this time, a and b are essentially pointers to strings. If you compare directly with ==, what is compared is actually the value address stored in the pointer. .

3. Variable types are different.

Python has six standard data types: Number, String, List, Tuple, Sets, and Dictionary. There are four types of number types: integers, Boolean types, floating point numbers, and complex numbers. C language can also be divided into four categories: basic types, enumeration types, void types, and derived types. Basic types: integer type, floating point type.

4. The methods of using function libraries are different.

To use that library function in C language, you need to introduce the header file using include, and when you need to introduce other modules or functions in python, you need to use import.

The different mechanism between the two is that include in C language tells the preprocessor that the contents of the file specified by this include should appear as a local source file, while import in python can be imported through a simple import , or import numpy as np.

5. Global variables are different.

In C language, declare global variables. If the value is constant, you can directly declare it with #define. If you only declare global variables and the value of the variable is variable, then it can be directly similar to int a. .

In python, when declaring a global variable, you need to add global, similar to global a. When using it in a function, you need to declare global a first. Otherwise, if a is used directly, python will re-create a new local object. And assign the new value to him, the value of the original global variable does not change.

Related recommendations: "Python Tutorial"

The above is the detailed content of The difference between c language and python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn