Python Learning 19th Day ternary operator differs from PHP language

Source: Internet
Author: User

Tags: SSE ternary conditional statement Network Print common need nbsp get

Ternary operators are shorthand for conditional statements, common conditional statements write three lines, ternary operators only need to write a line, how does the Python ternary operator write?

1, Common condition judgment

If a<b:

Print (a)

Else

Print (b)

2, ternary operator

Val=a if a<b else b

If a is less than B equals a

Otherwise equal to B

Ternary arithmetic of 3,php language

$id = Isset ($_get[' id ')? $_get[' ID ']: false;

The received ID exists $id = $_get[' id ') otherwise false

Article from (JIU le network http://www.96net.com.cn/)

Python Learning 19th Day ternary operator differs from PHP language

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: