5 Simple Differences Between JavaScript and Python

Photo by David Clode on Unsplash

I have begun the exciting journey of learning my first language post-bootcamp: Python! A senior engineer friend of mine once described learning new coding languages as “more like learning a new accent rather than an entire language” and so far I completely agree. There are more similarities then differences: variables work the same, there are the same data types (strings, integers, booleans, floats, etc.), string interpolation works the same…the list goes on and on. Once you understand the basic foundation of one language, the next one comes to you much more quickly and easily.

However, there are always going to be differences, especially in syntax. After spending a lot of time with JavaScript, here are my 5 main takeaways of things I have found that are different between JS and Python so far:

1. Print instead of console.log

Need to print something to the console? No more console.logs; simply type the command print() with whatever you wanted printed inside the parentheses.

print("Hello World") # Hello World

P.S. Want to comment out code in Python? Simply use the pound/hash sign (#), just like with Ruby.

2. Using Different Quotations in Strings is Crucial

Using quotes inside a string? Make sure to use different quotations (for example, single quotes and double quotes) so the computer can properly understand what needs to be printed.

print("Strings in Python are similar to strings in JavaScript, in that they are wrapped in quotation marks like so: 'Hello World'") # Strings in Python are similar to strings in JavaScript, in that they are wrapped in quotation marks like so: 'Hello World'

3. Use Underscores for Large Integers

If you have a very large integer that you would usually separate with commas, you can use underscores for better readability. Simply place them wherever you would normally place commas, like so:

large_int = 123_456_789
another_large_int = 1_000_000

large_int is the same as writing 123,456,789. another_large_int is the same as writing 1,000,000. The computer ignores the underscores, but it is extremely helpful for human eyes when trying to read large numbers.

4. Booleans begin with capitals.

This one felt a little bizarre to me at first, because booleans in both Ruby and JavaScript are all lowercase. In Python, the first letter is capitalized:

true_boolean = True
false_boolean = False

5. Division always returns a float.

When performing division in Python, you use the same symbol as JavaScript (/). However, with Python, division will always return a float rather than a plain integer.

print(10 / 5)   # 2.0

Characteristics like this are the reason why Python is a great choice when building applications that require a lot of math.

These are my main takeaways from learning just a couple of different Python methods and being introduced to Python data types. I have been really enjoying learning Python through Dr. Angela Yu’s Python course on Udemy, which you can check out here. As always, the Python documentation is also a great place to dig deeper. Happy coding!

Blaire is a musical theatre performer who also moonlights as a full-stack software engineer. https://www.linkedin.com/in/blaire-baker