Python Learning notes Clutter two

Source: Internet
Author: User

Input

>>>x=input (' Hint: ')

Output redirection


python2.7

>>>PRINT>>FP, "xxx" >>>fp.close ()

python3.5

>>>print (' xxx ', FILE=FP) >>>fp.close ()

A detail about for

>>>for I in range (3): Print (i) 012>>>for I in range (3): Print (i,end= ") 012 This means that Python's print function is the default At the end of \ n, when we use the For loop to print, pay attention to

Remark:1, programming takes precedence when using built-in functions to implement your own logical business

2. It is recommended to import only one module per import statement


Sequence

The reverse output is the last subscript-1, followed by 2,-3 ...

>>>a=[1,2,3]>>>b=a*3>>>b[1,2,3,1,2,3,1,2,3]

The slice operation does not throw an exception because the subscript is out of bounds, but simply truncates the tail of the list or returns an empty list, which is more robust.

>>>a=[1,2,3,4,5]>>>a[2:][3,4,5]>>>a[1,2,3,4,5]>>>a[:3][1,2,3]>>>a [1,2,3,4,5]>>>a[100:][] #返回一个空列表 >>>a[1,2,3,4,5]>>>a[:100:2][1,3,5] #在列表尾部截断 >> >a[1,2,3,4,5] #切片是浅复制, just assign values and not change the original list.

Things are too miscellaneous, are learning the time of 1.1 notes.

Python Learning notes Clutter two

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.