Boinx's Blog

Stepping stone

Fresh From Vacation

Python and Javascript

Python and Javascript are the two programming languages that I’ve learned during the Christmas Vacation. For me, Python is more confusing than Javascript because you don’t end your statements with semicolon and it doesn’t need to have curly braces in making functions and if/else statements. It relies on white spaces and indentions(which can be a little bit tricky when you’ve lost track of the indentions).

Example: IF/Else Statement in Javascript

    if(5>2){
    console.log("Yes");
    }else{
    console.log("No");
    }

IF/Else Statement in Python

    if 5 > 2:
        print "Yes"
    else:
        print "No"

The output of both the if/else statements is the same. We can see that in Python, we didn’t have to use open and close parentheses, curly braces and semi colons. However, it is more confusing than Javascript because if we’ve made a mistake on our indentions or spaces even just one white space or one tab space your program will end up having an error message. Now, I will show you how to declare variables on Python and Javascript.

Example: Declaring Variables in JavaScript

    var a = 5;
    var b =10;
    var c = a*b;

Declaring Variables in Python

    a = 5
    b = 10
    c = a*b

As you can see, Python doesn’t require you to put var when declaring variables while on JavaScript in order to declare a variable you need to specify that you’re declaring a variable by following this method: var variable_name = value. They can both also get input/s from the user without needing a form in html. We can do this by using the prompt for JavaScript and raw_input for Python.

Example: Getting input/s from user using JavaScript

var a = prompt("What is your age?");

Getting input/s from user using Python

a = raw_input("What is your age?")

That’s how you get input/s from a user using JavaScript and Python. Now, I’ll show you how to create functions using JavaScript and Python.

Example: Defining functions in Javascript:

function Boinx(args1,args2){
    return args1*args2
});

Defining functions in Python:

def Boinx(args1,args2):
    return args1*args2

That’s all for today. I just shared to you the basics in JavaScript and Python. It will take a lot of time if I’ll discuss everything I’ve learned from studying the two languages. I’ll study more languages and update this blog as soon as I’m finished.