Difference between C and Python

If you are a c or python developer then you should know these most valuable difference between c and python. Below most valuable 11 difference between c and python are given.
NumberCPython
1C is not object oriented languagePython is object oriented language
2C supports pointer.Python does not supports pointer.
3C is compiler dependent languagePython is interpreter dependent language
4Complied programs usually executes faster as compared to interpreted programs that why C is faster as compared to Python.Interpreted programs usually executes slower as compared to compiled programs that why Python is slower as compared to C.
5Error debugging is difficult as its compiler dependent language, it takes entire source code and compile it, then shows all error.Error debugging is simple. as its interpreted language, it takes only one in instruction at time and compile and execute simultaneously. if error is there it shows instantly and stops execution, at that instruction.
6In C, we need to mention return type of function.
void sum()
{
int a=20;
b=30;
printf("%d",a+b);
}

/*Here return type is void*/
In Python, we do not need to mention return type of function.
def sum():
  a=20;
  b=20;
  print(a+b);

/*No need of return type*/
7In C, We group statements using curly braces.
while(1)
{
int a=10;
printf("%d",a);
}
In python, We group statements using colon (:)
while 1:
  a=10;
  print(a);
8C is Free form of language means you can write statements anywhere on the line.
Example1:
int a=10;
float f=20.5;
/*Works fine in C.*/

Example2:
int a=10;
    float f=20.5;
/*Even this Works fine in C.*/
Python is an indentation language, means statements should start from the same column or same indent.
Example1:
a=10;
f=20.5;
/*Works fine in Python.*/

Example2:
a=10;
    f=20.5;
/*this doesn't Work in Python as a and b not started in same coloum or same indent.you will get error as unexpected indent*/
9In C you have to define variables type Explicitly.
Example:
int a;
float f=20.5;
/*In C we have to tell compiler a is integer and f is float by using keywords int and float respectively.*/
In Python you don’t have to define variables type Explicitly, Interpreter understands, variables type based on data whether it is integer or float or String.
Example:
a=10;
f=20.5;
10In C no need to initialize variable before we use.
Example:
int a;
print("%d",a);
//This works fine in c.
In python you have to initialize the value of variable where you define it.
Example:
a;
print(a);
/*This will not work in Python,You will get error message
a is not defined .*/
11C doesn't support Function renaming mechanism means we can't use same function by two different namesPython supports Function renaming mechanism means we can use same function by two or more than two different names.
Example:
def test():
   print("we are in test function");
dummy=test;/*Assigning reference of test to dummy*/
dummy();/*this will print we are in test function */
/*Function dummy() will behave same as function test()*/

You may also like...

Leave a Reply