Basic python & mdash; basic data type, python Data Type

Source: Internet
Author: User

Python basics-basic data types, python Data Types

Common functions of basic data types:

1. INTEGER (int)

  • Bit_length (self) # obtain the shortest binary digits that can be expressed
  • + ,-
X = 4
Print (x. bit_length ())


2. String (str)
  • Center # center format: a1.center (20 .'*')
  • Count # Number of occurrence times of the string neutron sequence: a1.count ("AB",) or a1.count ("AB ")
  • Endswith # Whether to end with AB, return True or Fales format: a1.endswith ('AB',) or a1.endswith ('AB ')
  • Startswith
  • Expandtabs # converts the Tab key (\ t) to a space key. By default, it is converted to eight spaces.
  • Find # find and return the location. -1 not found
  • Rfind
  • Format # convert the placeholder ({0}, {1} ·) in the string to the set value.
  • Join # concatenates strings in * join format: "***". join (a1)
  • Ljust # The content is left aligned and filled on the right, similar to the center format: a1.ljust (30 ,'*')
  • Must UST
  • Lower # Small write
  • Lstrip # Remove spaces on the left
  • Rstrip # Remove spaces on the right
  • Strip # Remove spaces on both sides
  • Partition # split, front, middle, and back. The returned result is of the tuples. Format: a1.partition ('AB ')
  • Rpartiton
  • Replace # replacement format: a1.replace ("AB", "cc", 1) replace the first AB from left to right with cc
  • Split # format: split ('E', 1)
  • Rsplit
  • Swapcase # case-insensitive Conversion
  • Title # title
  • Upper

Index

A1 [0]

A1 [1]

Len (a1) # Length

Slice

A1 [0: 2]

Loop

While I <len (s ):

A2 = a1 [I]

Or

For I in a1:

Print (I)

3. list)

Index

Slice

For Loop

  • Append # append format: list1.append ("abcd ")
  • Count # statistics format: list1.count ("abcd ")
  • Iterable # iteratable

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.