Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
68 views

Comparison Between Python and JavaScript

The document compares various functions and operations in Python and JavaScript. Some key points: - Both languages allow assigning variables, printing to the console, taking user input, and commenting code. - They have similar functions for getting string lengths, slicing strings, changing case, and creating functions. - JavaScript uses curly brackets for code blocks while Python uses indentation. - Both support control flows like if/else statements and include similar logic operators. - Both support data structures like lists and dictionaries/objects to store and access multiple values. - They have analogous methods for common tasks but use different syntax due to being different languages.

Uploaded by

Genius Code
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Comparison Between Python and JavaScript

The document compares various functions and operations in Python and JavaScript. Some key points: - Both languages allow assigning variables, printing to the console, taking user input, and commenting code. - They have similar functions for getting string lengths, slicing strings, changing case, and creating functions. - JavaScript uses curly brackets for code blocks while Python uses indentation. - Both support control flows like if/else statements and include similar logic operators. - Both support data structures like lists and dictionaries/objects to store and access multiple values. - They have analogous methods for common tasks but use different syntax due to being different languages.

Uploaded by

Genius Code
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

FUNCTION PYTHON JAVASCRIPT RESULT

 Assigning a name = "Abdurrahman" var name = "Abdurrahman"; Assign


variable variable:
name as
Abdurrahman
.
 Printing to the print(name) console.log(name); Displays
Console the name in
the
console.
 Prompting for an input ("How old are prompt ("How old are Asks you to
input you?") you?"); input your
age.
 Commenting code # How are you // How are you OR Makes a
/*How are you */ for particular
multiline comment. part of
your code
not to be
counted as
code.
 Getting length len(name) name.length; Gives the
length of
variable:
name
 Slicing name[0:1] --> A name.slice(0,1); --> A Gives you
the
characters
from index
0 to 1
excluding
1.
 Changing a string name.upper() name.toUpperCase(); Turns the
to an Upper Case name to an
Upper Case.
 Changing a string name.lower() name.toLowerCase(); Turns the
to a Lower Case name to a
Lower Case.
 Creating a def move(place): function move(place) { Creates a
function with return "go" + return "go" + function.
input and output place place
}
 Rounding to the Math.round(2.5)  3 Rounds the
nearest whole number into
number a whole
number.
 Rounding down Math.floor(2.5)  2 Rounds the
number down
to whole
number.
 Randomizing import random Math.random Generates a
between 0 to 1 random.random() 16 digit
number from
0 to 1
excluding
1.
 Randomizing random.randint(from, Randomizing
between a to) from a
particular number particular
to another number to
another to
give an
integer.
 To begin and end Use column ( ‘:’ ) Use Curly Brackets ( ‘{}’
a code like )
function, Control
flows.
 Using Control If track == "clear": If (track==="clear"){
Flows ( If and go_straight() go_straight();
Else Statement ) else: }else {
turn_right() turn_right();
}
 To check if an Use the ‘in’ keyword. Tag ‘.includes()’ to the
item is in an e.g.: variable.
element like list = ["Angelina", var list = ["Angelina",
lists. "Ballerina", "Ahmad"] "Ballerina", "Ahmad"]
if "Ahmad" in list:
print("welcome") if(list.includes("Ahmad")
{
alert("welcome")
}
 To add to a list list.append("Genius) list.push("Genius")
 To use two To use ‘or’: or To use ‘or’: or
conditions in a To use ‘and’: and To use ‘and’: &&
conditional.
 Creating a houseKeeper = { var houseKeeper = { Creates a
dictionary(Python "name": "Angela", "name": "Angela", dictionary
) or JavaScript "age": 35, "age": 35, or
Object. "yearstoUse": 12 "yearstoUse": 12 JavaScript
} } Object to
store
multiple
data.
 To tap into those We use square We use the dot notation.
properties that brackets that are e.g. housekeeper.age
are saved in the contained by the name
dictionary or of the variable used
JavaScript to store particular
Object. information. e.g.
housekeeper["age"]
NB: Using double ‘equals to’ sign to check for equality, checks if two
things are equal without considering the data type but three ‘equals
to’ will check their equality considering their data type.

You might also like