Use of Python strings (top)

Source: Internet
Author: User

#! /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)

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.