Python ternary operator

Source: Internet
Author: User
#比较大小更简单了x, y=3987,24361small= (x if x<y else y) print (small) #方法一: Compare the size of three numbers to find the larger one x,y,z=8,1,13if X<y:sma Ll=xelse:small=yif small<z:print (small) else:small=z print (small) #方法二: Compare the size of three numbers to find the larger one x,y,z=8,9,1small= (x If x<y else y) small= (small if small<z else z) print (small) #方法三: Compare the size of three numbers to find the larger one x,y,z=8,4,11small= ((x if x<y else Y) if (x if x<y else y) <z else z) print (small)

Python ternary operator

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.