The question says it.
Here's a little explanation.
In PHP. "==" works like this
2=="2" (Notice different type)
// True
While in python:
2=="2"
// False
2==2
// True
The equivalent for python "==" in php is "==="
2===2
//True
2==="2"
//False
Million dollar question. What is php "==" equivalent to in python?
In a word, PHP is meant for web and web only. Python, on the other hand, is infinitely more versatile. It can be used for web development, but also many, many other things.
You can run a python script via php, and outputs on browser. Basically you have to call the python script this way: $command = "python /path/to/python_script.py 2>&1"; $pid = popen( $command,"r"); while( ! feof( $pid ) ) { echo fread($pid, 256); flush(); ob_flush(); usleep(100000); } pclose($pid);
Python is better than PHP in long term project. PHP has low learning curve, it is easy to get started with PHP. Compare to PHP Python has lower number of Frameworks. Popular ones are DJango, Flask.
Each time a file is created or modified; Python converts the code into bytecode. This code compilation method makes Python quicker than PHP. PHP programmers can simply improve the speed of PHP applications by installing a variety of caching systems. By default, Python is a faster language.
Python doesn't coerce between types the way PHP does, mostly.
You'll have to do it explicitly:
2 == int('2')
or
str(2) == '2'
Python coerces numeric types (you can compare a float with an integer), and Python 2 also auto-converts between Unicode and byte string types (to the chagrin of many).
There isn't one. You need to convert types before checking for equality. In your example, you could do
2==int("2")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With