Python sample | PHP sample | ||
#!/usr/bin/python3 |
<?php |
||
Var | String |
a = "" a = '' a = """line1 line2""" |
$a = ""; $a = ''; $a = "line1 line2"; |
Number |
a = 1 b=1.0 |
$a = 1; |
|
List |
a=[1,2,3] |
$a = [1,2,3]; $a = array(1,2,3); |
|
Tuple |
a=(1,"2") |
$a = [1,"2"]; |
|
Set |
a={'a','b','c'} |
||
Dictionary |
a={"a":"aa","b":"bb"} |
$a = ['a'=>'aa','b'=>'bb'] |
|
Flow | if |
if a==1 : print("a=1") elif a==2 : print("a=2") else : print("a != 1, a != 2") txt = "The best things in life are free!" if "expensive" not in txt: print("No, 'expensive' is NOT present.") |
if ($a==1) print("a=1"); else if ($a==2) print("a=2"); else print("a != 1, a != 2"); |
for |
for x in "banana": print(x) |
||
while | |||
Function | type | type(a) | gettype($a); |
isinstance | isinstance(a,int) | ||
delete var | del a | unset($a) |