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

Python for Kids: Coding Made FUN Cover
Kids Learn Programming

The Python for Kids Book on Amazon

The Python for Kids: Coding Made FUN book was recently published on Amazon. Great way for every kid to learn programming.

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