I know javascript I have to learn python

 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:
ChatGPT

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

ConceptJavaScriptPython
Assignment==
Addition++
Subtraction--
Multiplication**
Division//
Modulus%%
Exponentiation** or Math.pow()**
Increment+++= 1
Decrement---= 1
Floor DivisionMath.floor(a / b)//
String Concatenation++

Comparison Operators

ConceptJavaScriptPython
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

ConceptJavaScriptPython
Logical AND&&and
Logical OR`
Logical NOT!not

Conditional Statements

ConceptJavaScriptPython
If statementif (condition) {}if condition:
Else statementelse {}else:
Else if statementelse if (condition) {}elif condition:
Ternary operatorcondition ? expr1 : expr2expr1 if condition else expr2

Loops

ConceptJavaScriptPython
For loopfor (let i = 0; i < 5; i++) {}for i in range(5):
For...of loopfor (let item of iterable) {}for item in iterable:
While loopwhile (condition) {}while condition:
Do...while loopdo {} while (condition)while condition: (use condition at end)

Functions

ConceptJavaScriptPython
Function declarationfunction name() {}def name():
Return statementreturn valuereturn value
Anonymous function() => {}lambda:

List/Array Methods

ConceptJavaScriptPython
Add itemarray.push(item)list.append(item)
Remove last itemarray.pop()list.pop()
Remove first itemarray.shift()list.pop(0)
Add first itemarray.unshift(item)list.insert(0, item)
Access item by indexarray[index]list[index]
Slicearray.slice(start, end)list[start:end]
Lengtharray.lengthlen(list)
Iterate over arrayarray.forEach()for item in list:

Object/Dictionary Methods

ConceptJavaScriptPython
Define objectconst obj = {}dict = {}
Access propertyobj.prop or obj['prop']dict['key']
Add propertyobj['key'] = valuedict['key'] = value
Remove propertydelete obj['key']del dict['key']
Iterate over keysfor (let key in obj) {}for key in dict:

String Methods

ConceptJavaScriptPython
Lengthstr.lengthlen(str)
Access by indexstr[index]str[index]
Substringstr.substring(start, end)str[start:end]
Splitstr.split(delimiter)str.split(delimiter)
Joinarr.join(delimiter)delimiter.join(list)
Findstr.indexOf(substr)str.find(substr)
Replacestr.replace(substr, newSubstr)str.replace(substr, newSubstr)

Miscellaneous

ConceptJavaScriptPython
Console outputconsole.log(value)print(value)
Parse integerparseInt(str)int(str)
Parse floatparseFloat(str)float(str)
String to lower casestr.toLowerCase()str.lower()
String to upper casestr.toUpperCase()str.upper()
Check typetypeof valuetype(value)
Create classclass 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