so mi have learnt javascript and now i am learning python so give me all operators, tag and methods which uses in python at the place of javascript
ChatGPT said:
That's great! Here is a comprehensive list comparing JavaScript and Python operators, methods, and constructs to help you transition from JavaScript to Python:
Basic Operators
Concept | JavaScript | Python |
---|
Assignment | = | = |
Addition | + | + |
Subtraction | - | - |
Multiplication | * | * |
Division | / | / |
Modulus | % | % |
Exponentiation | ** or Math.pow() | ** |
Increment | ++ | += 1 |
Decrement | -- | -= 1 |
Floor Division | Math.floor(a / b) | // |
String Concatenation | + | + |
Comparison Operators
Concept | JavaScript | Python |
---|
Equal to | == | == |
Strict Equal to | === | == |
Not equal to | != | != |
Strict Not equal to | !== | != |
Greater than | > | > |
Less than | < | < |
Greater than or equal | >= | >= |
Less than or equal | <= | <= |
Logical Operators
Concept | JavaScript | Python |
---|
Logical AND | && | and |
Logical OR | ` | |
Logical NOT | ! | not |
Conditional Statements
Concept | JavaScript | Python |
---|
If statement | if (condition) {} | if condition: |
Else statement | else {} | else: |
Else if statement | else if (condition) {} | elif condition: |
Ternary operator | condition ? expr1 : expr2 | expr1 if condition else expr2 |
Loops
Concept | JavaScript | Python |
---|
For loop | for (let i = 0; i < 5; i++) {} | for i in range(5): |
For...of loop | for (let item of iterable) {} | for item in iterable: |
While loop | while (condition) {} | while condition: |
Do...while loop | do {} while (condition) | while condition: (use condition at end) |
Functions
Concept | JavaScript | Python |
---|
Function declaration | function name() {} | def name(): |
Return statement | return value | return value |
Anonymous function | () => {} | lambda: |
List/Array Methods
Concept | JavaScript | Python |
---|
Add item | array.push(item) | list.append(item) |
Remove last item | array.pop() | list.pop() |
Remove first item | array.shift() | list.pop(0) |
Add first item | array.unshift(item) | list.insert(0, item) |
Access item by index | array[index] | list[index] |
Slice | array.slice(start, end) | list[start:end] |
Length | array.length | len(list) |
Iterate over array | array.forEach() | for item in list: |
Object/Dictionary Methods
Concept | JavaScript | Python |
---|
Define object | const obj = {} | dict = {} |
Access property | obj.prop or obj['prop'] | dict['key'] |
Add property | obj['key'] = value | dict['key'] = value |
Remove property | delete obj['key'] | del dict['key'] |
Iterate over keys | for (let key in obj) {} | for key in dict: |
String Methods
Concept | JavaScript | Python |
---|
Length | str.length | len(str) |
Access by index | str[index] | str[index] |
Substring | str.substring(start, end) | str[start:end] |
Split | str.split(delimiter) | str.split(delimiter) |
Join | arr.join(delimiter) | delimiter.join(list) |
Find | str.indexOf(substr) | str.find(substr) |
Replace | str.replace(substr, newSubstr) | str.replace(substr, newSubstr) |
Miscellaneous
Concept | JavaScript | Python |
---|
Console output | console.log(value) | print(value) |
Parse integer | parseInt(str) | int(str) |
Parse float | parseFloat(str) | float(str) |
String to lower case | str.toLowerCase() | str.lower() |
String to upper case | str.toUpperCase() | str.upper() |
Check type | typeof value | type(value) |
Create class | class ClassName {} | class ClassName: |
These tables should help you transition between JavaScript and Python by providing a direct comparison of the common constructs and methods used in both languages.
https://chatgpt.com/c/b35fe83b-64c7-4458-991c-07c28fb9ba4d url of chatgpt
Comments
Post a Comment