"Python" conditional judgment and looping with Dict and set

Source: Internet
Author: User

# Conditional Judgment

The role of Elif:else if

Note: "Colon"
BMI =w/(h*h)

If bmi<15:
Print (' lighter ')
Elif bmi<25:
Print (' normal ')
else BIM:
Print (' obese ')

# loops

For x in XS a bit like the C # foreach
Range () generates an integer sequence, range (101) generates an integer sequence of 0~100

While loop

Find different
One

n = one while n>10:    n-1    print(n)

Two

n = ten while n >:    = n-1    print('1', N)

The difference between one and two,,,

#dict和set

Dict Dictionary dictionary shorthand,

Key-value Storage,

Fast, indexed,

Advantages compared to list

    1. The speed of finding and inserting is very fast and will not increase with the increase of key;
    2. It takes a lot of memory, and it wastes a lot of memory.

Disadvantages:

    1. The time to find and insert increases as the element increases;
    2. Small footprint and little wasted memory.

Set and dict are immutable pairs of objects

Immutable objects--just change the value, the object itself does not change.

Where do you use it???

"Python" conditional judgment and looping with Dict and set

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.

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.