The difference in syntax (part) between php and python

PHP中文网
Release: 2016-03-30 17:08:26
Original
13982 people have browsed it

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("""   字符串   字符串 """)
Copy after login

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())
Copy after login

encoding:

php:

header('content-type:text/html;charset=utf-8');
Copy after login

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");
Copy after login
python: array = [] 或 array = [1,2,3]
Copy after login

add array

php:

array_push($arr, $val);
Copy after login

python:

array.append(val) #追加 或 array.extend(val) #合并
Copy after login

delete array elements

php:

array_pop(); 删除最后一个元素 array_shift();删除第一个元素
Copy after login

python:

array.pop()
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!