Compare C++ and Python Datatypes
Compare C++ and Python Datatypes
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
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:
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/