Python Beginner notes (progressive update)

Source: Internet
Author: User
Tags shallow copy

Python2 and Python3 in a little bit different, but for programming is not too big difference, in the release notes, Python2 official support until 2020, so when learning to use Python3 version: 1, the difference between print,    In Python2, you can use the print "name" directly, such expressions, in the Python3 must be bracketed, such as: Print ("name"), so more canonical. 2. Python character encoding support, in Python2, Unicode encoding is not supported (direct Chinese is supported), Utf-8 is a compression and optimization version of Unicode encoding, all character encoded versions are backwards compatible, and the compatibility relationship is as follows:ascii< The gb2312<gbk1.0<gb18030<unicode<utf-8 features are as follows: The Ascii:8 bit represents a byte, representing a maximum of 255 characters, 2**8-1=256-1gb2312: A total of 7,445 characters, of which 6,763 Chinese characters and 682 other characters, were produced in 1980 GBK 1.0: Included 21,886 symbols, which are divided into Chinese characters and graphic symbols area. The Chinese character area consists of 21,003 characters. 1995 Gb18030: Included 27,484 Chinese characters, but also included Tibetan, Mongolian, Uyghur and other major minority characters. 2000 Unicode: Universal code, characters and symbols denoted by 16 bits of 2 bytes, content in 2**16utf-8:ascii code is saved with 1 bytes, European characters are saved in 2 bytes, East Asian characters are saved in 3 bytes3, in the Python3 input and Python2 in the raw_input is the same effect. 4. Formatted Output
Info1 =" "-------Info of" "+ name +" "-------Name:" "+ name +" "Age :" "+ Age +" "Job:" "+ Job +" "Salary:" "+ Salary +" ""' #字符串拼接的方式 Info2 =" "-----Info2 of%s------Name:%Sage:%Djob:%ssalary:%F" "the s in% (name,name,age,job,salary) #%s means that string,d represents an integer type, and F represents a floating-point type Info3 =" "----Info3 of {_name}-----Name:{_name}age:{_age}job:{_job}salay:{_salary}" ". Format (_name=name, _age=age, _job=job, _salary=salary) Info4 =" "----Info3 of {0}-----name:{0}age:{1}job:{2}salay:{3}" ". Format (name,age,job,salary)
Four formats, the first of which is not recommended, because it is inefficient to allocate multiple memory spaces in memory. It is recommended to use the third, format specification. 5, in the loop, continue is to jump out of this cycle to continue execution, break is jumping out of the entire cycle. 6, the str type and bytes type conversion between, encode and Decode7, the list of copy method is called shallow copy, can only copy the first layer of the list. If deep copy is required, import copy will need to be manually specified in the Copy list, such as name1=copy.deepcopy (names), but requires a cool, independent memory space. There are three types of light copy: Name=copy.copy (names), name=names[:];name=list (names) 8, print (range (1,10,2)), and 2 print 1-10 digits. Print (Name[0:-1:2]), skip the list slices, 0 and 1 and omit, can be as follows, print (Name[::2]) 9, tuples can be called read-only lists, only count and index two method 10, the operation of a string is The identifier () method is to determine if it is not a valid identifier11.The dictionary is unordered and has no subscript. You only need to find it by key. Dictionary: Key-value. added in the dictionary, directly enter the Key-value value can be deleted in a variety of ways:del info["number"];info.pop["number"]Print (Info.get (' number ')) Safe lookup dictionary for content, if value exists return value, does not exist then feedback none

Python Beginner notes (progressive update)

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.