Basic Python knowledge and basic python tutorials

Source: Internet
Author: User

Basic Python knowledge and basic python tutorials

Python loop, if you already have programming experience, these are all trivial for you.

Names = ["Zhang San", "Li Si", "Wang Wu"] for name in names: print (name)

Python loops include not only the For loop, but also the While loop.

n=99while n>0:    n=n-1    print(n)

 

I will not display the display results because it is too troublesome to take screenshots and Import images.

How to Use Dict and Set

Dict operates through key-value pairs like JSON

Read content in Dict

Dics = {"a": "Zhang San", "B": "Li Si", "c": "Wang Wu"} print (dics ["a"])

 

Dics = {"a": "John", "B": "Lee"} print (dics. get (""))

Deletes an element of Dict.

Dicts = {"a": "John", "B": "Lee"} dicts. pop ("")

Similar to dict, set is also a set of keys, but does not store values. Because keys cannot be repeated, there are no duplicate keys in the set.

>>>st=set([1,2,3,4])>>>st{1,2,3,4}

Add set

St. add (5)

If the same element is added, the filter is performed.

St. add (4)

Show {1, 2, 3, 4}

Set deletes an element.

St = set ([1, 2, 4])

St. remove (1)

{2, 3, 4}

List Sort

>>> A = [,]

>>> A. sort ()

[,]

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.