0% found this document useful (0 votes)
103 views15 pages

Python C Python Comparing

Python-C-python-Comparing-PPT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views15 pages

Python C Python Comparing

Python-C-python-Comparing-PPT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Name of the School: School of computer science and engineering

Course Code: Course Name : PROGRAMMING FOR PROBLEM-SOLVING

Topic:

Python and C programming Comparison and its


pros and cons

Faculty Name: R.MUTHU GANESH Programe Name:


Prerequisite/Recapitulations

We assume that the Students have a reasonable exposure to any


programming environment and knowledge of basic concepts such as
variables, commands, syntax, etc.
Objectives

In this session we learn the differences between C and Python in detail, let us have an overview of some of the
most fundamental differences between C and Python. C is a compiled language, whereas Python is an
interpreted language. Python follows the Object-Oriented Programming paradigm, whereas C is a Structured,
Procedure Oriented Programming language.
Introduction to C

The C language was developed at Bell Labs between 1972 to 1973. The computer scientist Dennis Ritchie
founded it. The C language was primarily developed for building and running programs on top of the Unix
operating system. To know more read History of C Language

It was used to re-implement the kernel of the Unix operating system. Nowadays, C is used to develop various
applications and firmware, implement portable systems, etc.

The C language aids a variety of features like structured programming, lexical variable scope, and recursion, with
a static type system, etc.

C offers the traits of high-level languages as it aids us in writing programs that do not depend on a certain
computer type, and the traits of low-level languages as it aids us with computer architecture with minimal or
negligible. Thus C is also known as mid-level language.

It provides many features like structured programming, lexical variable scope, pointers, etc.

C is a middle-level language because it binds the gap between machine-level and high-level languages. A user can
use c language to do System Programming (for writing operating systems) and Application Programming (for
generating menu-driven customer billing systems).
Introduction to Python

Python is a general-purpose, high-level language that is interpreted. It has gained popularity among programming
languages over the years. Python was released to provide descendant to the ABC programming language in 1991.
Python has introduced indentation, which has been a pioneer in improving code readability. Some of the
programming paradigms provided by python are:

Object-Oriented Programming: Object-oriented programming (OOP) is a programming style characterized by


identifying classes of objects closely linked with the methods (functions) with which they are associated. It also
includes ideas of inheritance of attributes and methods.
Functional Programming: Functional programming is a programming paradigm in which we try to bind
everything in pure mathematical functions. It is a declarative type of programming style.
Structured Programming: Structured programming is a programming paradigm that facilitates creating programs
with readable code and reusable components.
Introduction to Python

Python is strongly typed and a dynamically typed language, i.e., the variable type matters when an operation is
performed on a variable. Dynamic typing means that the variable type is determined only during runtime. Python
frees the space that is not being used and reclaims the block of memory; thus, it is also garbage-collected.

Python has become popular because of its abundance of features and is used in different fields in the industry. One
of the biggest reasons for its popularity is the user-friendliness and simple syntax, thus making its learning curve
comparatively low.

Python is a very high-level programming language because its syntax so closely resembles the English language.
Higher-level means it's more readable to humans and less readable to computers.
Key Difference Between C and Python

Comparison Parameter C Python


Programming model C is a procedural programming language. C Python is an object-oriented
programs follow a procedure of steps written in it, programming language.
called functions. It follows a top-down approach, Everything in python is an object.
i.e., much importance is given to the flow of the Using python, we can create
program rather than to data on which functions classes and objects.
operate

language type C does the work of filling the gap among the The Python is translated into
machine-level languages and high-level languages. machine language with an
Thus it is also known as mid-level language. interpreter. Thus it is also known
as high-level language.
Python Defining a Function

Comparison Parameter C Python


Compilation and C is a compiled programming language. Python is an interpreted
Interpretation It uses compilers to check the whole C programming language. It uses
code in one go, and the errors detected interpreters to check each line of the
in the C code during this process are Python code, and if an error is
reported at once. detected anywhere within the code,
it stops the interpretation of the
program at that moment
Speed Since Python programs are
Since the C program is compiled thus, it
interpreted thus, it is comparatively
is a faster language than Python.
slower than C programs.
Declaration of variable In Python, we do not need to define
The variables in C are declared when the variable's data type when it is
they are created. The values assigned declared. Such variables are also
to these must be of the known as untyped variables. The
particular type of the variable. values of distinct data types can be
stored in python variables.
Key Difference Between C and Python
Comparison Parameter C Python
Memory Management The memory management in
In C, we need to do the memory management python is handled automatically with
manually. the help of the Garbage Collector
available.
Pointers The Python language does not have
The C language has the support for pointers.
them for support pointers.
Functional Units Since C is a procedural programming Since Python is an object-oriented
language, thus most of the functional units in programming language, thus most of
C are functions. the functional units are objects.
Robustness Python is a relatively more robust
C is a relatively less robust language than
language than C as it has very rugged
python.
memory management schemes.
Applications The C programming language is mostly used Python is a general-purpose
to develop hardware applications. programming language
Key Difference Between C and Python

Comparison Parameter C Python


Availability of built-in The C language has a very limited The Python language has a huge
functions number of built-in functions. collection of built-in functions.
Usage of Data Structures Data structures in C (e.g., stack, Data Structures in Python are
queue, etc.), needs to implement by available with built-in libraries; thus
the programmers to be used. it is comparatively easier to use.
In-line assignment. In C, we can do the inline
Python does not provide the feature
assignments. E.g., int temp = 11;
of inline assignment. E.g., temp = 11;
would assign the value 11 to temp in
with throw a python error.
C.
Program file type The C code files are stored in the The Python code files are stored in
system with the .c extension. the system with the .py extension.
Pros and Cons of C

Pros:
Faster Execution Speed: Since C is compiled, it often delivers faster performance than interpreted
languages.
Direct Memory Access: C supports pointers, providing a mechanism for direct memory access and
manipulation, which can lead to more efficient programs.
Closer to Machine Level: Being a mid-level language, C allows for low-level operations and is
commonly used for system programming and hardware applications.

Cons:
Manual Memory Management: Developers need to handle memory allocation and deallocation, which
can lead to memory leaks and other issues.
Less Built-in Functions: C has fewer built-in functions compared to modern high-level languages,
which may increase development time.
Less Robust: Without careful programming, C can lead to issues like buffer overflows, making it less
robust in certain scenarios.
Pros and Cons of Python (pointers)

Pros:
•Object-Oriented: Python’s object-oriented design simplifies many programming tasks and
structures.
•Memory Management: Python’s garbage collection system automatically manages memory,
reducing the risk of memory leaks.
•Huge Library Support: Python offers extensive built-in functions and libraries, enabling faster
development for a wide range of applications.

Cons:
•Slower Execution: Being an interpreted language, Python often runs slower than compiled languages
like C.
•No Pointers: Python does not support pointers, which might be a disadvantage for certain system-
level programming tasks.
•Overhead: Due to its high-level nature, Python may introduce more overhead than languages like C
in terms of memory and processing.
Conclusion

C is a procedural programming language

Python is an Object-oriented programming language

The C language provides better performance and is used in systems where high speed and
performance are required.

Python is a general-purpose language that can be used to ease development and in problems where
code reusability is of great value.

The Python language has a vast collection of built-in functions compared to the C language.
Python is a general-purpose language, whereas C is used in developing hardware applications.
C is relatively less robust than Python
C allows in-line assignment.
C has the support for pointers, whereas python does not support pointers.
Python has automatic memory management whereas, in C, the memory management needs to be done
manually.
Practice Questions

1. Write a C code to find the Maximum of these two numbers.

Input: a = 2, b = 4
Output: 4

Input: a = -1, b = -4
Output: -1

2. Find the Factorial of a Number Using Recursive approach.

3. All programs written in python should be converted in C code.


References

Let Us C by Yashavant P. Kanetkar BPB Publications

Swayam/NPTEL/MOOCs:
https://onlinecourses.swayam2.ac.in/cec22_cs20/preview

https://onlinecourses.nptel.ac.in/noc22_cs32/preview

You might also like