python string processing 2

If mystr has at least one number, and all characters are letters or numbers, return true, otherwise return false (in fact, I found that no numbers are true)

mystr.isalnum ()

  Returns true if mystr has at least one character and all characters are letters (without numbers and spaces), otherwise false

mystr.isalpha()

  true if mystr contains only decimal digits, false otherwise

mystr.isdecimal()

  Returns true if mystr only contains numbers and only numbers, otherwise returns false

mystr.isdigit()

  Returns true if mystr contains at least one case-sensitive character and all of those characters are lowercase, false otherwise.

mystr.islower()

  Returns true if mystr contains only numeric characters, otherwise returns false

mystr.isnumeric()

  true if mystr contains only spaces, false otherwise

mystr.isspace()

  Returns true if mystr is titled (see title), false otherwise.

mystr.istitle()

  Returns true if mystr contains at least one case-sensitive character and all of these case-sensitive characters are uppercase, false otherwise.

mystr.isupper()

  Insert str after each character in mystr to construct a new string

mystr.join(str)

  Returns a new string left-aligned and padded with spaces to width (used to extend the length of the string)

mystr.ljust (width)

  Returns a new string with the original string right-aligned and padded with spaces to width (used to extend the length of the string)

mystr.rjust(width)

  Truncate spaces to the left of mystr

mystr.lstrip()

 remove spaces at the end of mystr

mystr.rstrip()

 Similar to the find() function, but searches from the right.

mystr.rfind (str, start = 0, end = len (mystr))

  Similar to index, but starts from the right.

mystr.rindex (str, start = 0, end = len (mystr))

  Divide mystr into three parts, before str, after str, and after str

mystr.partition(str)

  Similar to the partition() function, but starts from the right

mystr.rpartition (str)

  Split by row, return a list with each row as an element

mystr.splitlines()

  Returns a string of length width, the original string mystr is right-aligned, and the front is filled with 0

mystr.zfill(width)

  Check if a string contains only decimal characters, this method only exists on unicode objects.

mystr.isdecimal()

  To define a function, the function block begins with the def keyword, followed by the function identifier name, parentheses ( ) and:

Pass parameters by value and pass parameters by reference

1. Pass parameters by value, a single variable.

2. Pass by reference (if you modify a parameter in a function, then in the function that calls the function, the original parameter is also modified, for example)

parameter

The following are the formal parameter types that can be used when calling a function:

Required parameters

named parameters

Default parameter

variable length parameter

 

Required parameters

  Mandatory parameters need to be passed into the function in the correct order, and the number must be the same when called as declared.

       When calling the printme() function, a parameter must be passed in, otherwise a syntax error will occur.

named parameters

  Named parameters are closely related to function calls. The caller uses the parameter names to determine the incoming parameter values, which can be skipped.

  At this time, formal parameters and actual parameters do not necessarily correspond one-to-one. You can specify what to pass in by parameter name.

Default parameter

  When calling the function, the value of the default parameter is considered to be the default value if it is not passed in. (Although 5 is defined, 5 is the default value. If b is not passed in anything, use 5)

It is true that parameters cannot go from left to right, that is to say, you cannot only assign default values ​​to the values ​​on the left, and not assign them to the right. At this time, the interpreter will report an error.

The default parameters are from right to left.

variable length parameter

  

If the variable-length transfer parameter is a *, it will be automatically matched as a tuple, and if it is **, it will be automatically matched as a dictionary 37

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324884168&siteId=291194637