#! /usr/bin/env python#-*-coding:utf-8-*-#basic usage of stringsTest ="Freesince{number}{name}"#Capitalize first letterPrint(Test.capitalize ())#so the letter becomes lowercase casefold () more powerfulPrint(Test.casefold ())Print(Test.lower ())#set width and center content to width Fillchar for fill character" "Center (Self, width, fillchar=none) Self can ignore the width parameter directly fillchar=none if the parameter is not filled in with a default value (empty) " "Print(Test.center (20,"¥"))#count How many occurrences of this character appear in the character starting with the first (starting at 0 including the end bit, which is >=3)Print(Test.count ("e", 3))#decide whether to end with whatPrint(Test.endswith ("e"))#decide whether to start with whatPrint(Test.startswith ("F"))#finding the position of a field 4 means greater than or equal to 4 9 means less than 9 or less than or equal to 8Print(Test.find ("Since", 4,9))#assigns a placeholder in a string (part of the curly brace) to a valueTest1 ="{0}{1}{2}"Print(Test.format (number ="number 1th", name ="Baby"))Print(Test1.format (" kill, Kill, kill.","whoa , whoa."," ah ah ah ah ah"))#determine that there are only letters, numbers in the stringTest2 ="123"test3="SDAs"test4="Das45sda45"Print(Test2.isalnum (), Test3.isalnum (), Test4.isalnum ())
Run results
Use of Python strings (top)