Here's a comparison of PHP and Python syntax in a table format
| Feature | PHP | Python |
|---|---|---|
| Comments | // Single-line comment<br>/* Multi-line comment */ | # Single-line comment<br>''' Multi-line comment ''' |
| Variables | $variable_name | variable_name |
| Variable Assignment | $variable = value; | variable = value |
| Data Types | Dynamic typing | Dynamic typing |
| Strings | "Double quotes"<br>'Single quotes' | "Double quotes"<br>'Single quotes' |
| Concatenation | . | + |
| String Interpolation | "Hello $name" | "Hello {name}" |
| Arithmetic Operators | +, -, *, /, % | +, -, *, /, % |
| Comparison Operators | ==, !=, <, >, <=, >= | ==, !=, <, >, <=, >= |
| Logical Operators | &&, ` | |
| Control Structures | if, else, elseif, switch, while, for, foreach | if, else, elif, while, for, foreach |
| Arrays | $array = array(1, 2, 3); | array = [1, 2, 3] |
| Array Access | $array[0] | array[0] |
| Associative Arrays | $array = array("name" => "John"); | array = {"name": "John"} |
| Functions | function functionName() { ... } | def function_name():<br>\t... |
| Function Arguments | functionName($arg1, $arg2) | function_name(arg1, arg2) |
| Classes | class ClassName { ... } | class ClassName:<br>\t... |
| Class Methods | public function methodName() { ... } | def method_name(self):<br>\t... |
| Class Properties | $property | self.property |
| Exceptions | try { ... } catch (Exception $e) { ... } | try:<br>\t...<br>except Exception as e:<br>\t... |
| File Inclusion | require_once('filename.php'); | import module_name<br>from module_name import * |
| Regular Expressions | /pattern/ | re.compile(r'pattern') |

Comments
Post a Comment