Python B1 Basics

Source: Internet
Author: User

In the above code,%s is a placeholder, also called the formatting of a string. Integer is%d, floating-point number is%f, but%s can include all, why not%s ... Also less remember things, so lazy ...

The number of%s in quotation marks in print is the same as the number of variables in% () outside the quotation mark.

Os.system (cmd) or os.popen (CMD), the former return value is the exit status code of the script, and the return value of the latter is the output of the script during execution. Actual use is subject to demand.

List && Dict

L1 = List (range (5)) L2 = List (range (5)) L2.extend (L1) print (L1) print (L2) D1 = {' A ': 1, ' B ': 2}d2 = {' d ': 4, ' e ': 5}D2.UPDA Te (d1) print (D1) print (D2)

  

Analytical:

User_info=json.load (Open (' User_info ', ' R '))        #读数据json. Dump (Goods,open (' Goods_info ', ' W '), Ensure_ascii=false, indent=1)    #写入数据

wherein, ensure_ascii=false means not to transcode, if the data has Chinese, there is no ensure_ascii parameter, will be garbled. The indent is indented to make the data look more orderly and elegantly loaded with laws.

Sort: sort_keys=true, sorting makes the data look more orderly, although the dictionary is unordered, and the egg ...

file using load, Python object using loads

+ Addition

-Subtraction

* Multiplication

/Division

% modulo, remainder, left divided by the right, the return value of the resulting residue

* * exponentiation

Divide the left by the right, and wait for the integer part

Break jumps out of the loop

Continue skip this time and continue to the next cycle

Have to say f.writelines strong, note the parameter is a list, list, list, important things to say three times!!!

In addition to List.remove (), Del, Del also applies to variables, lists, dictionaries, and so on, can also be deleted multiple:

Sort () Sorts the list, but in Py3, numbers and strings are not sorted when they appear in the list at the same time.

All say is the evil of the plus ' + ', can not be used, then use join, the object can be strings, lists and so on

Dic.fromkeys ([1,2,3,4], ' test ') just borrowed a dictionary for this import, the original dictionary and no eggs

d1={' name ': ' Ccorz ', ' age ': +, ' company ': ' It '}res=d1.fromkeys ((1,2,3,1), ' Test ') print (res) #只是借用字典的功能而已print (D1) # The result didn't change the original dictionary.

Set ()

S.discard () If there are no elements in the collection, do not error, there are elements, delete

Python B1 Basics

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.