Python Boolean and List

Source: Internet
Author: User

BOOL the Essence

In Python, the Boolean type is inextricably linked to the 0 and 1 of the int type.

true = = 1; false = = 0;

And the Boolean type can be calculated as a numeric value, such as:

x = 3 + True

x = 4

Boll (obj) function: You can convert an object to a Boolean value. is commonly used for true-truth testing, where the object is converted to false only in the following situations:

0 or 0.0;

None

empty string, empty list, empty tuple, empty dictionary.

Lists List

Can contain an ordered collection of arbitrary objects.

Elements can be accessed by subscript index (position offset).

Variable length, heterogeneous, can be nested arbitrarily.

Supports in-situ changes.

An array of object references.

Append (obj) method: You can add content to a list.

List (obj) function: Global to convert an object to a list.

Common operations for sequences:

In operator: can be used to determine whether an element exists in the list.

Not in operator: Determines whether the element does not exist in the list.

Connection sequence: S1 + s2

Repeating sequence elements: S * n

Subscript get element: S[i]

Access the specified index range: s[i:j]

Access the specified index range by step: s[i:j:k]

Get sequence Length: Len (s)

Get Minimum value: min (s)

Get maximum value: Max (s)

Sum of statistics: sum (s)

Retrieves the position of the first occurrence of an element subscript: S.index (x)

Number of Statistics element occurrences: S.count (x)

Common operations for variable sequences:

Elements in a mutable sequence can be changed in place by the index, or the values of elements within a particular index range can be changed, but when the scope changes, the given parameter must be an iterative object.

SYNTAX:S[I:J] = [XX,XX,XX]

Supports changing the original element to more placeholders or a placeholder element.

For example:

x = [11,12,13,14]

X[:2] = [1,2,3,4,5]

Or

X[:2] = [1]

Other than that

To add a step parameter to a range retrieval, the content of the new element provided must be the same as the number of elements in the sequence to be modified.

To delete an element:

Del operator: can be used to delete sequences of individual elements, range elements, and elements of a certain step in the range.

S.remove (x): Used to delete the first matching value.

S.clear (): Clears the sequence.

Append element:

S.append (x) method: The contents in parentheses are only used as an object to be added to the sequence.

Extended sequence:

S.extend (x) method: Multiple elements can be placed in parentheses.

Insert element:

S.insert (i,x) method: Use to specify the index of the element to be changed in parentheses.

New words:

Gender [? d?? ND?R] Gender profile [? Pro?? FA?L] Profile Image Overview Data Graph score score points

Import imports introduced maths (math) to the floor bottom of the math floors. Ceil ceiling round [ra?nd] round integers around about defined [d?? FA?ND] A clear define to ... Defined, clarified, defined. decimal [? d?s (?) M?L] Decimal Decimal

interrupt [? n (t)?? R?PT] Interrupt interrupted, occlusion. Count number of counts. Attempt [?? T?m (P) T] attempt. sequence [? Sikw?ns] series, sequence, sequence. Extended [? k?st?nd?d] extension, provided. Slice [sla?s] cut, thinly sliced, partly. Extend [? k?st?nd] extension. Invalid [?? NV?L?D] Invalid of the sick.

Python Boolean and List

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.