Some common methods of type int, bool type complement, and string in Python

Source: Internet
Author: User

One, int type

Bit_length () returns a binary length of a number

II. type of bool

A Boolean has only two values. True,false. Generally there is nothing to do with it.

All empty is false, so the non-null is True

Iii. Types of str

The contents of the ",", "", "" are the strings.

A string is an immutable data type. No matter what you do. The source string will not change, and each operation will return a new string

1. Indexes and slices

Index starting at 0, using [subscript] to get to each character, you can also count backwards

Slice: [Start position: End Position: Step]

1. Gu Tou regardless of the tail

2. Default left-to-right values

3. When the step is negative, you can take the value from right to left

2. String-related operations

1. Upper () converted to uppercase
2. Stript () Remove blank
3. Replace (old, new) with XXX to XXXX
4. Split () cut. Returns the list. With how long the knife. How much will it cost?
5. StartsWith () Decide whether to start with XXX
6. Find (), count (), index ()
7. Len () string length. Python's built-in functions

3. For loop
The for variable in can iterate over the object:
Loop body, there are also break and continue
Else
When the loop ends, it executes.

 

  

  

Some common methods of type int, bool type complement, and string in Python

Related Article

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.