Show Menu
Cheatography

Scala to Python Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Variables

foo = 'Apples'
val foo = "­App­les­"
baz = foo + ' and oranges'
val baz = foo + ' and oranges'
baz = "Only Grapes­"
Vals are immutable in Scala. Create a var instead
one = 1
var one = 1
one += 1
one += 1
foo, bar = [1, 2, 3], [1,2,3]
val foo, bar = Array(1, 2, 3)
foo[0] = 4
#Changes only foo
bar(0) = 4
// changes only bar
foo.__­add­__(4)
foo.+(1)
 

Control Statements

foo = 1 if x > 0 else -1
val foo = if (x > 0) 1 else -1
if x == 0: 
  baz = 5
if (x == 0) { 
baz = 5
}
 
if (foo.i­sIn­sta­nce­Of[­Str­ing]) { 
print(­"Foo is a string­!")
} else if (foo.i­sIn­sta­nce­Of[­Int]) {
print(­"Foo is an int!")
} else {
print(­"I dont know what foo is...")
}
 
while (n < 5) { nlist += n n += 1 }