Python Learning 4

Source: Internet
Author: User

1. Use Set () function to show only unique elements. And we can add () and remove () in a set. Also, it is allowed to use list () to change set into a list

2. User try/except to avoid errors in the program.

3.enumerate () function:

Animals = ["Dog", "Tiger", "Superlion", "Cow", "Panda"]
viciousness = [1, 5, 10, 10, 1]

For I, animal in Enumerate (animals):#In The list animals, I was the index of each elements, animal in the element Corre Spond to each element.
Print ("Animal")
Print (animal)
Print ("viciousness")
Print (Viciousness[i])

4.List comprehensions

5.The items () method:

Plant_types = {"Orchid": "Flower", "Cedar": "Tree", "Maple": "Tree"}
For types,rating in Plant_types.items (): # Here we use items () to avoid access both keys and values on dictionaries.
Print (types)
Print (rating)

Python Learning 4

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.