Home>Article>Backend Development> The difference in syntax (part) between php and python

The difference in syntax (part) between php and python

PHP中文网
PHP中文网 Original
2016-03-30 17:08:26 13965browse

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()
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to configure PHP Next article:How to configure PHP

Related articles

See more