Home > Article > Backend Development > The difference between python and c
The differences between python and C are as follows
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.
The above is the detailed content of The difference between python and c. For more information, please follow other related articles on the PHP Chinese website!