Home >Backend Development >PHP Tutorial >The difference in syntax (part) between php and python
this chapter will introduce some of the grammatical differences between php and python. it has certain reference value. friends in need can refer to it. i hope it will be helpful to you.
heredoc syntax
php $a = <<< str 字符串 字符串 str; python print(""" 字符串 字符串 """)
character case control
//php (strtolower(str),strtoupper(str))$a = "hello world";print(strtolower($a)); //python (str.lower(), str.upper())a = "hello world"print(a.lower())
encoding:
php:
header('content-type:text/html;charset=utf-8');
python:
#encoding=utf-8 or #coding:utf-8 in order to highlight the great artistic talent of programmers often written as # -*- coding:utf-8 -*- python3 defaults to utf-8
array operations:
create array
php: $array = new array(); 或 $array = array("a"=>"a","b"=>"b");
python: array = [] 或 array = [1,2,3]
add array
php:
array_push($arr, $val);
python:
array.append(val) #追加 或 array.extend(val) #合并
delete array elements
php:
array_pop(); 删除最后一个元素 array_shift();删除第一个元素
python:
array.pop()