Python core programming 4-sequence: String, list, And tuples

Source: Internet
Author: User

Python core programming 4-sequence: String, list, And tuples

1. Sequence member relationship operator (in, not in)


2. Sequence type operators

Functions of sequence Operators
Seq [ind]Obtain the element whose subscript is ind.
Seq [ind1: ind2]Obtains the set of subscripts from ind1 to ind2.
Seq * exprRepeated expr times
Seq1 + seq2Connection sequence seq1 and seq2
Obj in seqDetermine whether the obj element is included in seq
Obj not in seqDetermine whether the obj element is not included in seq


3. Join operator (+): concatenates a sequence with another sequence of the same type.


4. Repeated operators (*)


5. type conversion

Function Description
List (iter)Convert an iteratable object to a list
Str (obj)Convert an obj object to a string (String Representation of the object)
Unicode (obj)Convert an object to a Unicode string (using the default encoding)
Basestring ()Abstract Factory functions only provide the parent class for str and unicode functions, so they cannot be instantiated or called.
Tuple (iter)Converts an iteratable object into a tuples.


6. String formatting symbols

Format character conversion method
% C is converted to a character (ASCII value, or a string of one length)
% Ra converts strings with the repr () function first.
% S String Conversion using the str () function
% D/% I to a signed decimal number
% Ub to unsigned decimal number
% Ob to unsigned octal number
% Xb/% Xb (Unsigned) to Unsigned hexadecimal number (x/X indicates the size of the converted hexadecimal character
Lowercase)
% E/% E into scientific notation (e/E control output e/E)
% F/% F is converted to a floating point number (the fractional part is naturally truncated)
% G/% G % e and % f/% E and % F
% Output %


7. built-in functions cmp (), len (), max (), min (), zip (), enumerate ()

>>> S, t = 'foa', 'obr'
>>> Zip (s, t)
[('F', 'O'), ('O', 'B'), ('A', 'R')]


8. Python does not have the end character nul of the c style. How many characters do you enter? What is the return value of the len () function.


9. Three quotation marks

It can contain line breaks, tabs, and other special characters.


10. The function can return multiple objects.

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.