Python Learning (iii)

Source: Internet
Author: User

Index and slice of a string

1. Index

Set existing string s= ' ABCDEFG ', s[0] to start position, S[-1] as end

2. Slicing

 

What is a data type

int: Used to calculate

BOOL: Judging

STR: Small amount of data, operable

List: Storing large amounts of data, such as [1,2,3,4, ' Andraw ', [[+]]

Ganso: can also store large amounts of data, read-only, ("Asda")

Dict: Dictionary {' name ': ' ASD ', ' age ': ' 55 '}, Dictionary {' Andraw ': [1,3,5,2]}

Key-value pair form, strong relationship, fast query

Collection: {1,2,3,4, ' Adsas '}

Conversions between data types

1, int turn bool

0 is false, not 0 is true

2, str turn bool

"is false, non-NULL is True

int operation method

Bit_lenght (): The bit is converted to the minimum number of bits required in binary

String manipulation methods

Capitalize (): Capitalize first letter

Upper (): Letter to full capitalization

Lower (): letter converted to full lowercase

Swapcase (): Case Flip

Title (): a space or special character including the first letter of a number separated by uppercase

Center (): How much width, center content, can set padding, default blank padding

Expandtabs (): \ t appears in the string, then the preceding string is complete with 8 bits, more than 8 bits, then complete 16 bits

Startwith (): Detects what begins with, satisfies then returns True, for example: S.startwith ("a"), starting with A; can be sliced, for example: S.startwith (' e ', 2,6), starting from 2nd bit, ending at 5th place , starting with E

Find (): detects whether the string contains the string, exists to return the location index, does not exist return-1

Index (): detects if character creation contains the string, there is an index to return the position, there is no error

Strip (): Remove the left and right spaces, or set their own special characters, the default space, can be removed at the same time multiple, such as S.strip ("-#"), remove the left and right spaces,-, and the # character

COUNT (): detects how many strings are checked, returns the number, does not return 0, for example: count ("Al"), detects how many of the strings are in AL

Split (): Splits the string into the list you need, for example; s= "a b c D", S.split (), default space split, cut into [' A ', ' B ', ' C ', ' d ']

Replace (): Replace the old word A with a new string, the default is full replacement, you can add a number last, decide to replace several

Isalnum (): A string consisting of letters or numbers

Isalpha (): string consisting of letters

IsDigit (): string consists of numbers

Python Learning (iii)

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.