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

How Python Differs From Other Languages 2

The document compares Python to other programming languages including Java, JavaScript, and C++. It discusses differences in features like code structure, variable declaration, data types, operators, and input/output between Python and these languages. Python is highlighted as being easier to learn and having more extensive libraries than some other languages.

Uploaded by

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

How Python Differs From Other Languages 2

The document compares Python to other programming languages including Java, JavaScript, and C++. It discusses differences in features like code structure, variable declaration, data types, operators, and input/output between Python and these languages. Python is highlighted as being easier to learn and having more extensive libraries than some other languages.

Uploaded by

Meron
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Addis Abeba Institute of Technology (AAIT)

COMPUTER PROGRAMMING INDIVIDUAL


ASSIGNMENT
Section 11
Name: Meron Birhanu
ID: UGR/2314/15

Instructor: Daniel Abebe


Submission date: July 21, 2023

1
How python differs from other languages
Python is a very popular programming language. It is designed to be accessible. This makes writing
python code easy. An advantage of Python is the wide selection of libraries frameworks it offers.

There are python libraries for:

• Machine language
• Data science
• Data visualization
• Natural science processing
• Data analysis
• Game development, and much more

Some python frameworks:

• Django
• Flash
• Pyramid
• Twisted
• Falcon

One flow of python is the runtime. Relatively slow when compared to other languages. There is a
workaround for this flaw. When performance is a priority, python gives the ability to integrate other
languages, with higher performance into the code.

Python intuitive to read, especially for English speakers. It doesn’t require as many lines code as java or
c. python’s simplicity is particularly helpful in code readability. Because python code has fewer lines and
is English like reviewing it takes less time. Python is also scalable and easy to learn.

Comparing python with other languages

Python is compared with the most liked programing such as

• Java
• Java script
• C++
• C
• Perl
• Swift

2
Python compared with Java
Both python and Java are excellent and very popular programming languages. Despite their differences,
they both stand out for their powerful cross-platform support as well as for their extensive libraries.
However, they do excel in different applications.

Feature python Java


Language Interpreted Language - it can Compiled and Interpreted
instantly convert human- Language - can be considered
readable code into machine- both since its source code is
readable code. compiled into a binary
bytecode, which in turn runs on
the JVM (typically a software-
based interpreter).
Typing Dynamically typed Statically typed
Syntax Less code - the developer does More code - the developer must
not require to type in the type in all the variables and
variables since these are input have very rigorous syntax rules.
during the runtime; does not
need enclosing braces or
indentation rules.
Performance Compiles the code at runtime, Java compiles code in advance
thus being not as agile and distributes the bytecode.
regarding compilation with
every platform.
Stability Python tests the syntax during Higher stability - Since
the runtime everything has to be reviewed
and established before running
Applications Scientific and numeric Web applications; Desktop GUI
computing; Machine Learning Apps; enterprise solutions;
applications; image processing; embedded systems.
language development.
Speed Fast development due to the Java projects tend to take
easiness, simplicity and longer and may require larger
practicality to write in Python. development teams.
Learning Easier to learn - Suitable choice Takes longer to learn - There is a
for beginners since its syntax is learning curve with a high entry
easy and clear. point.
Multiple Inheritance Python supports multiple Java partially supports Multiple
Inheritance. Inheritance through interfaces.

Python allows for indentation for writing blocks with multiple lines, but Java needs to insert the lines
inside of curly brackets to establish and define a method or a block.

For example: In python

3
# Declaring variables
x, y = 12, 10
isTrue = True
greeting = "Welcome!

But in Java
public class Main {
public static void main (String[] args) {
// Declaring variables
int x = 12, y = 10;
boolean isTrue = true;
String greeting = "Welcome!";

Other simple syntax code examples that demonstrate the difference between
python and java
Hello world:

• Python:

Print( “Hello, world!”)

• Java:

Class HelloWorld {

Public static void main(string[] args) {

System.com.println(“Hello, World!”);

Variable declaration:

• Python:

X=5

• Java

int x = 5;

4
Python compared with JavaScript
Python and JavaScript are very powerful languages with different syntax and real-world applications.

We will see the differences in their main elements

➢ Code Blocks in Python and JavaScript

How Python defines code blocks

Python relies on indentation to define code blocks. When a series of continuous lines of code are
indented at the same level, they are considered part of the same code block. These are some examples:
Use of indentation to define code blocks in Python

How JavaScript defines code blocks

In contrast, in JavaScript we use curly braces ({}) to group statements that belong to the same code
block.

These are some examples: Use of curly braces to define code blocks in JavaScript

➢ Variable Definitions in Python and JavaScript


How to define a variable in Python

To define a variable in Python, we write the name of the variable followed by an equal sign (=) and the
value that will be assigned to the variable.

Like this:

<variable_name> = <value>

For example:

x=5

How to define a variable in JavaScript

The syntax is very similar in JavaScript, but we just need to add the keyword var or let before the name
of the variable and end the line with a semicolon (;).

Like this:

5
var <variable_name> = <value>; For example: var x = 5; or let x = 5;

➢ Variable Naming Conventions in Python and JavaScript

In Python, we should use the snake_case naming style. In contrast, we should use the lowerCamelCase
naming style in JavaScript. The name starts with a lowercase letter and then every new word starts with
an uppercase letter.

➢ Data Types and Values in Python and JavaScript

Numeric Data Types

Python has three numeric types to help us perform precise calculations for scientific purposes. These
numeric types include: int (integers), float (floating-point numbers), and complex. Each one of them has
its own properties, characteristics, and applications.

In contrast, JavaScript has only two numeric types: Number and BigInt. Integers and floating-point
numbers are both considered to be of type Number.

➢ How to Write Comments in Python and JavaScript

➢ Operators in Python and JavaScript

In Python, the floor division operation (also called "integer division") is represented with a double slash
(//).

In JavaScript, we don't have a particular floor division operator. Instead, we call the Math.floor() method
to round down the result to the nearest integer.

The == operator in Python works like the === operator in JavaScript.

➢ Logical Operators

6
In Python, the three logical operators are: and, or, and not.

In JavaScript, these operators are: &&, ||, and ! (respectively).

➢ Input and Output in Python and JavaScript

➢ Output

Conclusion
• Python is easy to learn as compared to JavaScript.
• JavaScript can be used for native application development whereas Python can be used in the
domains like machine learning and data analysis.
• Python contains a lot of libraries which makes the code smaller and easy to understand whereas
there are few libraries in JavaScript as compared to Python.
• The structure of both the programming languages is completely different as Python uses
indentation for its code structure whereas JavaScript uses semicolons and curly braces.
• JavaScript can be used both on the server and on the browser, while Python is a language that is
mostly used for server-side programming.

7
Python compared with C++
Python and C++ are two different languages that have different features and different behaviors. Both
these languages have one thing in common i.e., strong support for object-oriented programming.

#1) Compilation
C++ is a compiled language. C++ compiler generates an object code from the C++ source code and is
then executed to produce the output. Python is an interpreted language. The Python code with an
extension Py need not be compiled. We can directly pass it to the Python interpreter and generate the
output.

#2) Usage
C++ has a lot of features and has a comparatively difficult syntax. It is not that simple to write the C++
code. Python is easy to write and has a clear syntax. Hence writing Python programs is much easier
when compared to C++.

#3) Nature of Language


C++ is a statically typed language i.e., the declaration of a variable, the data type of variables, etc. are
verified at compile time. This keeps the source code error-free at runtime. Python, on the other hand, is
not statically typed. There is no type checking done at compile time. Hence, the code is prone to errors

#4) Portability
C++ is not portable i.e., we need to recompile the code on every different platform. C++ is mainly “Write
Once, Compile Anywhere". Python is portable. It is also cross-platform, and we can execute programs on
any platform.

#5) Garbage Collection/Memory Management


In C++, memory management is manual. C++ does not support automatic garbage collection of
resources. Python, on the other hand, has a feature of automatic garbage collection. Its memory
management is system controlled.

#6) Rapid Prototyping


We cannot do rapid prototyping using C++. Using Python, we can do rapid prototyping of code so that it
can be used later for building applications using higher-level languages.

#7) Installation
C++ can be easily installed on Windows. Python, however, is difficult to install.

#8) Efficiency
C++ code is difficult to maintain as it can get complicated to read as solutions become bigger.

8
Python, on the other hand, has clean code and simple syntax. The source code for Python is easier to
maintain.

#9) Speed of Execution


As far as speed of execution is concerned, C++ programs run faster. In fact, C++ is known and used
widely in applications that are required to run faster like gaming platforms.

Python, on the other hand, runs slowly. Moreover, Python programs run slower than Java programs.
Hence, we employ Python specifically for applications that can compromise on speed.

#10) Syntax Complexity


In C++ there is a clear demarcation of the code by using blocks enclosed in {}, semicolons indicating the
end of the statement, etc. Thus, in C++, the syntax is well organized.

In Python, there are no blocks or semicolons. Instead, Python uses indentation.

Some examples based on syntax

Python C++
Indentation if x > 5: if(x>5) {
Print(“x is greater than 5”) Count<< “x is greater than
5”<<end|
}
Variable declaration name = “John” string name = “John”
age = 25 int age = 25
Printing output print(“hello, world!”) count << “hello, world!”
<<end|;
Loops for I in range(5): for(int I =0; I < 5; I++) {
Print(I) Count << I << end|;
}
Input name = input(“enter your #include <iostream>
name”) Using name space std
Int main() {
String name;
Count << “enter your name:”;
Cin >> name;
Return 0;
}

9
Python compared with C
Python and C languages are useful languages to develop various applications

What are the Similarities Between Python and C Language?

• Both are High-level programming languages.


• Both languages can be used to implement Multithreading.
• Both languages can be used for embedded systems programming.
• C is a foundation language for many languages including Python.

What are the differences between python and C language?

• Architecture
Python is an interpretive, high-level, general-purpose, and multi-paradigm programming language. And
C is a well-known example of a procedural programming language with many applications in several
fields.

• Execution
Python provides dynamism by using an interpreter to run all programs and execute code. And The way
that C works is by first compiling the code before running the program or code fragment

• Variable Declaration
Given that Python is one of the loosely typed programming languages, it is not necessary to mention the
variable type. And before a variable is used in the program in any form, it must first be declared in C.

• Debugging
Python is renowned for its interpreter architecture, and when an error occurs, the program will not run.
And even though there are problems, C must compile the entire program despite them before
displaying it to the user.

• Built-in Functions
Numerous built-in functions in Python allow for the simplification of a wide range of activities. And
comparatively fewer functions are available in C, which significantly lengthens the program overhead
and code.

• Multiple Variables
Lists, dictionaries, sets, tuples, and more data types are supported by Python. And Only the common
data types, including int, float, char, and others, are supported by C.

• External Libraries

10
There are countless libraries for Python in every field, including AI, ML, gaming, web development, etc.
And There are some good libraries for working within C, but not quite as many as there are in Python.

• Garbage Collection
Python provides built-in features for automated garbage collection and other memory-handling
operations. And Any type of automated garbage collection or other automated memory management
operations are not supported in C.

• Frequent Prototyping
Python was created specifically to give developers access to tools and settings that facilitate quick
prototyping. And Prototypes cannot be quickly scaled into production or efficiently used to drive a
product using the C language.

• Syntax
Python uses whitespace to structure code, and C uses curly braces and semicolons to structure code

• Applications
Python is a general-purpose programming language and C is generally used in hardware related
applications.

Python C
Printing statements Print(“Hello, world!”) Printf(“Hello, world!\n”);
Variable declaration ‘x = 10’ ‘int x =10’
Variable types int, float, string int, float, string, ‘short’, ‘long’
‘unsigned’
Functions def square(x): int square(int x) {
return x* x return x*x;
result = square(5) }
Print(result) int main() {
int result = square(5);
printf(“%d\n”, result);
result 0;}
Conditions and loops X=5 int main() {
If x > 0: Int x = 5
print(“positive”) if (x>0) {
elif x == 0: Printf(“positive\n”);
Print(“zero”) }
Else: else if (x == 0) {
Print(“negative”) Printf(“zero\n”);
}
else {
Printf(“negative\n”);
}

11
12
Python compared with Perl
Perl Python
It is a high level, interpreter based, general It is a high level, interpreter based, general
purpose dynamic programming language purpose programming language.
Perl aimed to simplify the report making process Python aimed at simplifying the code writing
which later went through a lot of changes and process to write simple and logical code for small
revisions to include many new features and and large projects and applications.
capabilities.
Perl code is not very simple as compared to code Python code is simpler and easier to understand.
written in Python.
Perl has an impressive support of libraries and so Python needs the support of third-party libraries
can handle Operations at OS level using built-in to handle such operations.
functions.
The OOP support offered is limited. Python has a great support for Object Oriented
Programming.
Code blocks are marked and identified using Code blocks are marked and identified by the use
braces. of indentation.
Whitespaces do not hold a significance in Perl In python whitespaces hold a significance and can
cause syntax errors.
It allows for easy text processing as support for Python requires the use of external functions to
Regular expressions is a part of Perl language. handle Regular expressions.
Perl uses semicolon(;) to end a code line. Semicolons (;) are not required at the end of each
code line.
Perl Vs Python – Code Comparison
Below is a piece of code written in Perl and the same code written in Python. The code adds two
numbers that are accepted as user input.

Code Example

Perl code example:


// Take User Input
Print “\n Input the first number”;
$N1 = <STDIN>;
Print “\n Input the second number”;
$N2 = <STDIN>;
// Call the subroutine
addition( $N1, $N2 );
// Move parameters to variables, add the numbers and display the result
sub addition {
$a = $_[0];
$b = $_[1];
$sum = $a + $b;

13
print "The sum of numbers entered is: $sum ";
}

Python code example:


// Accept User Input

N1 = input(‘Enter the first number: ’)

N2 = input(‘Enter the second number: ’)

// Adding of the Numbers

Sum = float(N1) + float(N2)

// Display of the Result

print(‘The sum of the numbers is:’ ,Sum)

Conclusion

As we have seen above, we have given some of the differences between Python and Perl. Both Python
and Perl are good in their regard as per the applications they target. Python is a bit better than Perl as a
first option for a beginner due to its ease and clean understanding of code.

14
Python compared with swift
What is the difference between python and swift?

• Definition
Python is a general-purpose object-oriented programming language., Swift is a powerful, general-
purpose, and compiled programming language

• Developed by
Python is developed by Guido Van Rossum in 1991., and swift is developed by Apple Inc in 2014.

• Performance
Python Slower in comparison to Swift., and swift Faster in comparison to Python

• Used For
Python is Mainly used for back-end development. And swift Mainly used in the software for the Apple
ecosystem.

• Market Demand
Python developers are in high demand than Swift developers. Swift developers are in less demand than
Python developers.

• Popular Companies
Python Using Technology Intel, IBM, NASA, Netflix, Facebook, Spotify, etc. Swift used in Uber
Technologies Delivery Hero SE, Slack, Lyft, etc.

• Supported language

Java, R Language, PHP, JavaScript, Anaconda, Scala, Perl Python, C language, JavaScript, C++, Ruby, Go,
C#, Rust etc.

Python Swift
Printing “Hello, world!” Print(Hello, world!”) Print(“Hello, world!”)
Declaring and initializing X=5 Var x = 5
variables Y = “Python” Var y: string = “swift”
Conditional statements (if-else) If x < 10: If x < 10 {
Print(“X is less than 10”) Print(“x is less than 10”)
else } else {
Print(“x is greater than or Print(“x is greater than or
equal to 10”) equal to 10”)
}

Looping through range of For I in range(5) For I in 0..<5 {


numbers Print(I) Print(I)

15
Function definition and calling Def greet(name): Func greet(name: string) {
Print(“Hello, “ + name + “!”) Print(“Hello, \(name)!”
Greet(Alice) }
Greet(name: “Alice”)

16

You might also like