0% found this document useful (0 votes)
9 views

Compare C++ and Python Datatypes

The document compares C and Python programming languages across various attributes including character sets, keywords, data types, variables, operators, control structures (if-else and while loops), basic I/O, and method creation and calling. C is statically typed and requires explicit type declarations, while Python is dynamically typed and infers types at runtime. The syntax and readability of control structures and I/O functions also differ significantly between the two languages.

Uploaded by

Sadip Neupane
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Compare C++ and Python Datatypes

The document compares C and Python programming languages across various attributes including character sets, keywords, data types, variables, operators, control structures (if-else and while loops), basic I/O, and method creation and calling. C is statically typed and requires explicit type declarations, while Python is dynamically typed and infers types at runtime. The syntax and readability of control structures and I/O functions also differ significantly between the two languages.

Uploaded by

Sadip Neupane
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Compare following attributed based on two widely used

programming language C-programming language and


python programming language

1. Character Set
2. Keywords
3. Data types
4. Variables
5. Operator
6. If else
7. While loop
8. Basic I/o
9. Method creates and call
1. Character Sets
 C Language: C uses the ASCII (American Standard Code
for Information Interchange) character set, which
includes letters, digits, punctuation, and control
characters. C is case-sensitive.
 Python: Python also uses ASCII by default but
supports Unicode, allowing for a wider range of
characters, including non-English characters.

2. Keywords
 C Language: C has a fixed set of keywords
(e.g., int, return, if, else, while, for, etc.). These
keywords cannot be used as identifiers.
 Python: Python has its own set of keywords
(e.g., def, class, if, else, elif, while, for, etc.).
Python's keywords are also reserved and cannot be
used as identifiers.
3. Data Types
 C Language: C is statically typed, meaning that data
types must be declared explicitly
(e.g., int, float, char, double). It has primitive types
and allows for user-defined types (structs, unions).
 Python: Python is dynamically typed, meaning that
data types are determined at runtime. Common data
types include int, float, str, list, tuple, dict, etc.

4. Variables
 C Language: Variables must be declared with a
specific type before use. For example: int a; declares
an integer variable a.
 Python: Variables do not require explicit declaration
of type. You can simply assign a value to a variable,
and Python will infer its type. For example: a =
10 automatically makes a an integer.
5. Operators
 C Language: C supports a wide range of operators,
including arithmetic (+, -, *, /), relational (==, !
=, <, >), logical (&&, ||, !), and bitwise operators.
 Python: Python also supports similar operators, but
with some differences in syntax and behavior. For
example, Python uses and, or, and not for logical
operations instead of &&, ||, and !.
6. If-Else
 C Language: The syntax for if-else statements is as
follows:

if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false

 Python: The syntax for if-else statements is more


readable and uses indentation:
python
1if condition:
2 # code to execute if condition is true
3else:
4 # code to execute if condition is false
7. While Loop
 C Language: The syntax for a while loop is:
1while (condition) {
2 // code to execute while condition is true
3}

 Python: The syntax for a while loop is:

1while condition:
2 # code to execute while condition is true
8. Basic I/O
 C Language: C uses functions like printf for output
and scanf for input:
1printf("Enter a number: ");
2scanf("%d", &number);
 Python: Python uses the print() function for output
and input() for input:
python
1number = input("Enter a number: ")
9. Method Create and Call
 C Language: Functions are defined with a return type
and can be called by their name. Example:

1int add(int a, int b) {


2 return a + b;
3}
4
5int result = add(5, 3);
 Python: Functions are defined using the def keyword
and can be called by their name. Example:
python
1def add(a, b):
2 return a + b
3
4result = add(5, 3)
Reference

1. C Language
(Stroustrup, 2013)

https://en.cppreference.com/w/c
https://www.learn-c.org/

2. Python Language
(Savitch, 2016-07-22 Paperback)

(Ramalho, 2015)

https://docs.python.org/3/

You might also like