Luffy-python Development Training-2nd Chapter

Source: Internet
Author: User

Learning experience:

Notes:

Print (Bin (343)) #0b101010111 returns the binary representation of an integer

Python2 the encoding that is supported by default is ASCII

Python3 the encoding supported by default is UTF8

Scientific counting Method:

Print (1.2395e8) #123950000.0   E8 represents 10 of 8 times, this E to large e is OK

Floating point number:

Floating point accuracy issues:

Integers and floating-point numbers are stored internally in different ways, and integer operations are always accurate and floating-point arithmetic can have rounding errors.

Python's default 17-bit precision, which is 16 digits after the decimal point, has 16 digits, but the accuracy is less than the future.

If you want to use more accurate floating-point numbers, you can introduce the "GetContext" and "decimal" Methods of the Decimal module.

List operations:

li=['python','PHP', 888,'Java','ABC', 888,'python','Alex']li.insert (1,666)Print(LI)#[' Python ', 666, ' PHP ', 888, ' Java ', ' ABC ', 888, ' python ', ' Alex ']Num=li.index ("PHP")Print(num)#2Num=li.count ("python")Print(num)#2N=LI[-4:-1]#The numbers inside the section brackets are small and large.Print(n)#[' ABC ', 888, ' python ']Li.remove (888)#If there are duplicates, delete is from the left number of the first, inside the parentheses must have parameters, pop can have no parametersPrint(LI)#[' Python ', ' PHP ', ' Java ', ' ABC ', 888, ' python ', ' Alex ']N=li.pop ()#without indexing, delete the last one, and return the deleted elementN2=li.pop (0)#delete the specified index elementPrint(n)#AlexPrint(N2)#pythonPrint(LI)#[' PHP ', ' Java ', ' ABC ', 888, ' python ']

The #sort () method is to sort the list itself, which can be added with a reverse parameter

Li.clear () #清空列表
Print (LI) #[]

The range () method also gets a list.

Each element in the list corresponds to a memory address, using the ID () method to look at the memory address.

List-Exercises

1. Create an empty list named names and add the Old_driver,rain,jack,shanshan,peiqi,black_girl element to it2. Go to the names list and insert a black_girl in front of Alex.3change the name of Shanshan to Chinese, Shanshan.4. Insert a sub-list after rain in the names list, [Oldboy, Oldgirl]5. Returns the index value of the Peiqi6. Create a new list [1,2,3,4,2,5,6,2], merge into names list7. Remove the index from the names list 4-Elements of 78. Remove the index from the names list 2-10 elements with a step size of 29. Remove the last 3 elements of the names list10. Loop names list, print index values for each element, and element11. Loop names list, print the index value of each element, and the element, when the index value is even, change the corresponding element to 112there are 3 2 in names, please return the index value of 2nd 2. Do not human flesh number, to dynamically find (hint, find the first 2 position, on this basis to find a 2nd)13The list of existing items is as follows: Products= [ ['Iphone8', 6888],['MacPro', 14800], ['Xiaomi 6', 2499],['Coffee', 31],[' Book', 80],['Nike Shoes', 799]] You need to print out this format:---------Product List----------0. Iphone86888 1. MacPro 14800 2. Xiaomi 6 2499 3. Coffee 31 4. Book 80 5. Nike Shoes 79914. Write a loop, constantly ask the user what to buy, the user selects a product number, the corresponding product added to the shopping cart, end user input Q exit, print the shopping cart list of items
View Code

Solving:

Luffy-python Development Training-2nd Chapter

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.