Python Influence on Scala

Python Influence on Scala
The changes that were introduced with the release of Scala 3.x indicate, probably more than ever, about the influence Python has on Scala.

Share This Post

The strong influence Python has on Scala could already be felt long time ago, before the emergence of Scala 3.0. When using the collections Scala supports, we cannot avoid the deja vu feeling that takes us back to Python. With the emergence of Scala 3.x, many new capabilities and changes were added to Scala and increased its resemblance to Python

Creating new Objects

As of Scala 3, you can create objects without using the new reserved word, similar to Kotlin and Python programming languages. In the following example, in line 1, the class named Rectangle is defined. In line 3, a new object is created.

				
					class Rectangle(var width:Double,var height:Double)

val rec:Rectangle = Rectangle(3,4)
				
			

Define new Classes and Methods

Similar to Python, as of Scala 3.x, you can define new classes, and instead of using curly brackets to create the block, use a uniform space (similar to Python) in each of the lines that make up the block, and add colons to the line before the block. Similarly, uniform spacing can be used in each line as a substitute for using curly brackets, also in the definition of traits and objects. Similarly, you can use uniform spacing in each line as a substitute for using curly brackets, also in the definition of methods.

				
					class Rectangle(var width:Double, var height:Double):
  def area():Double = 
    var result = this.width * this.height
    result
  def perimeter():Double =
    var result = 2 * (this.width + this.height) 
    result 
    
object RectangleDemo {
  def main(args: Array[String]):Unit =
    println("testing program")
    var rec1:Rectangle = Rectangle(3,4)
    print("area of rectangle is ")
    print(rec1.area())
}
				
			

You can find few more similarities. However, these are probably the most significant ones. The cleaner syntax we have as of Scala 3.x doesn’t simplify the language itself. Scala is still a static type programming language with more capabilities comparing with Python. 

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Java Catching Up
Java

Java’s Most Recent Updates

During the last decade, the Java programming language continued to evolve. We can assist you catching up with these new features.

OpenAI API Course
Artificial Intelligence

Using The OpenAI API

OpenAI provides us with API we can use in order to add AI capabilities to the software we develop. Join our course and learn how to do it.

Do You Want To Boost Your Business?

drop us a line and keep in touch

life michael academy asynchronous online courses

Java | Python | JavaScript | TypeScript

Skip to content Update cookies preferences