Python Learning essay (i)

Source: Internet
Author: User

first, String Learning

1 # Create a String method 2 ' ABC ' 3 # or 4 str1 = str ('abc)
1 # string First letter lowercase to uppercase, original uppercase unchanged 2 2 str2 = str1.captilize ()3print(str2)--   ABC
1 # capitalize the first letter of the string into lowercase, lowercase 2 ' ABC ' 3 str2 = str1.casefold ()4print(str2)---  ABC
 1  #   In the string drama, the first argument is to set the string width, the second parameter is the padding character on both sides, and the default is a space  2  str1 = str ("  abc   " )  3  str2 = str1.center (20, '  
 1  #   Counts the number of characters in a string, the first argument is a character, the second, the third argument is the start and end index  2  str1 = str ("  abcdgellsllxosngsewwlfalnaaan   '  
 1  #   Change the string to another encoding format, the parameter is the format you want to encode  2  str1 = str ( "  abcdgellsllxosngsewwlfalnaaan   " Span style= "color: #000000" >)  3  str2 = Str1.encode ("  utf-8   " "  4  print  (str2)-- > B " abcdgellsllxosngsewwlfalnaaan " Span style= "color: #800000" " 
 1  #   Reads whether the payment string ends with a character, The first argument is a character, the second, the third argument is the starting index, and returns a Boolean value that does not write the two or three parameter  2  str1 = str ( " abcdgellsllxosngsewwlfalnaaan  "  )  3  result = Str1.endswith ( '  l   ", 5,25 4  print  (result)--False 
 1  #   Converts the ' \ t ' character in a string to a space, the parameter is the space character width to convert, and does not set the default to 8  2  str1 = str ("  abcdgellsllx\tosngsewwlfalnaaan   " )  3  str2 = str1.expandtabs (10"  4  print  (str2)-- > Abcdgellsllx Osngsewwlfalnaaan 
 1  #   Finds the position of a character in a string from left to right, returns the index position, does not return 1, The first argument is a character, and the second and third argument is the starting index  2  str1 = str ( Span style= "color: #800000" > " abcdgellsllxosngsewwlfalnaaan   " )  3  result = Str1.find ( '  s   " )  4  print  (result)-8 
 1  #   Format the string, corresponding to the formatted string by location  2  str1 = str ( " Span style= "color: #800000" >zhushanwei {0} {1}   " )  3  str2 = Str1.format ("  is   ",  " handsome   " )  4  print  (str2)-zhushanwei is  handsome 
 1  #   Find the index of a character in a string, return it, the argument is a character  2  str1 =  "  lasgiongfa457af   " 3  result = Str1.index ("  4   " )  4  print  (result)---
# determines whether a string consists of numbers or letters, returns a Boolean value ' LASGIONGFA457AF '  = str1.isalnum ()print(result)---  True
1 # determines whether a string is composed of letters, returns a Boolean value 2 ' LASGIONGFA457AF ' 3 result = str1.isalpha ()4print(result)  -->false
# determines whether a string is a decimal number, returns a Boolean value ' 4575 '  = str1.isdecimal ()print(result)---   True
# determines whether a string is an integer, returns a Boolean value ' 4575 '  = str1.isdigit ()print(result)---   True
1 # returns a Boolean value that determines whether a string is a valid character, such as a variable that cannot begin with a character such as a number, @, etc. 2 ' 4575 ' 3 result = str1.isidentifier ()4print(result)---   False
# determines whether the string is lowercase and returns a Boolean value ' Abcnon '  = str1.islower ()print(result)----  False

Python Learning essay (i)

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.