Learning Python with a background in JS

Skabe89
2 min readAug 12, 2021

--

While I’ve been looking to jumpstart my career in tech I’ve seen a few reoccurring patterns in job postings. One, “Entry Level” can mean ANYTHING, from 0–2 years experience all the way to 5–10. Two, a lot of employers are still unsure of when they are returning to the office. Three, 75% + job postings mention Python. Post graduation from Flatiron I’ve been focusing on honing the skills I learned during the program, but due to the amount of jobs I could apply for (with an actual chance of getting through to the next level) with Python in my repertoire, I’ve finally decided to dive in a bit.

Since I come from a background in JS, and since I’ve just barely gotten into learning Python, this blog will go over very basic Python syntax from the perspective of someone who knows JS.

One of the first things that’s different is Python uses snake case whereas JS conventionally uses camel case.

JS => roundOfApplause
Python => round_of_applause

The first thing we’ll learn is how to print “Hello World!” in the output window on a Python sandbox (http://pythonsandbox.com/). Just like we would use console.log() in JS, print() does something very similar in Python.

print("Hello World!")

When you run the code the output will display exactly what we want.

Next we’ll discuss variables in Python. Instead of prefacing a variable with “const”, “let”, or “var”, you simply equate a variable name to a value.

greeting = "Hello World!"
print(greeting)

That code will output the same “Hello World!” as we previously did. You can think of every variable in Python kind of like “let” in JS, you can change the values as you go. *(You can assign constants in Python, but it’s a little more complicated”)

greeting = "Hello World!"
print(greeting)
greeting = "Goodnight Moon"
print(greeting)

The output of the previous code will be

Hello World!
Goodnight Moon

The last thing we’ll go over in this blog is how to write a simple function.

JS     => function sayHi(){
return "HELLO!!!"
{
console.log(sayHI())Python => def say_hi():
return "HELLO!!!"
print(say_hi())

With Python “def” replaces “function” while an opening “:” replaces “{“. Python functions don’t need a closing “}”. If you need to use an argument you can do it like this.

def say_hi(name):
return "Hello " + name
print(say_hi("Bob"))
print(say_hi("Jon"))
print(say_hi("Tina"))
output =Hello Bob
Hello Jon
Hello Tina

Very similar to JS, we declare an argument in this case “name”. Then we simply use name in the function return line. Finally when we call the function we use the name we want between the “()” and we get the personalized greetings.

I hope this set you up with a basic understanding of how to get started writing simple lines of code using Python!

--

--