Getting Started with Python learning notes

Source: Internet
Author: User

Hex: 0x123

Boolean operation: And, OR, NOT null: None Comment: #raw字符串不需要转义: R ' xxx ' multiline character: ' ' xxx ' ' multi-line character +raw string: R ' ' xxx ' Unicode character: U ' Chinese ' If the Chinese string encounters unicodedecodeerror in a Python environment, this is because there is a problem with the format saved by the. py file. You can add comments on the first line:#-*-Coding:utf-8-*-List:l = [A, B, c]list Add new element: L.pop (d), L.insert (0, D) List Delete element: L.pop (), L.pop (2) Tuple: Tuple once created, it cannot be modified: T = (A, b, c) single Tuple: t = (A,) for loop: for name in L: Dictionary dict: = {a:1, b:2, c:3} access Dict:d[key], D.get (key) Traverse dict:for key in d:set:s = Set ([ A, B, C, c]) = = Set ([A, B, c]) update Set:s.add (x), S.remove (x) define function: Def my_func (x): Returns multivalued: Return a, b defines default parameters: Def my_func (x = ' Hello ' '): Define a mutable parameter: DEF fn (*args): The variable parameter has an * number in front of the name and can pass in 0, one or more parameters to the variable parameter. Slice list: L[:3]l[::2]: The 3rd parameter indicates that the step distance is 2. The range () function creates a sequence: range (1, +) in Python, iterating over the element itself rather than the index of the element. Index iterations: Enumerate () function: L = [(1, a), (2, B), (3, C)] for index, value in enumerate (L):d The values () method for the ICT object: D.values () iterative di CT key and Value:for key, value in D.items ():p rint [x * x for x in range (0, 100)] string can be formatted with%: s = "%s%s"% (' hello ', ' world ') word The join () method of a string can be used to stitch a list into a string.

Getting Started with Python learning notes

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.