Python string manipulation

Source: Internet
Author: User

#!/bin/python#-*- coding=utf-8 -*-import stringprint ("Hello,world") str1 =  "        python is dynamic language         "#打印str1原型print (STR1) #打印去掉两边空格print (Str1.strip ()) #字符串大小写转换str2 = "Abcd efg,this is a test" Print (Str2.lower ())   #小写print (Str2.upper ())   #大写print (Str2.swapcase ())   #大小写互换print (Str2.capitalize ())  # Initial Capital Print (String.capwords (str2))   #将字符串用空格区分, and then capitalize the first letter print (Str2.title ())   #同string. Capwords () print ( Str2.find ("A", 2,15))   #返回 "A" where the sequence number, if not found return -1print (Str2.rfind ("a"))   #从右边开始寻找print (Str2.rindex ("a", 2,18))   #指定范围, no error was found print (Str2.count ("E"))   #统计寻找到字符的个数print (Str2.replace ("A", "Y") print (Str1.strip (). Replace (" ", "="))   #去掉两边空格print (Str1.lstrip (). Replace (" ", "=")   #去掉左边空格print (Str1.rstrip (). Replace (" ", "="))   #去掉右边空格str3  =  "123abcEFG" str4 =      "str5 = " "Print ( Str3.startswith ("AB"))   #是否以 "A", returns True or Falseprint (Str3.isalnum ())   #是否全为数字或字母print (Str5.isdigit ()) #是否全为数字print ( Str3.isalpha ())   #是否全为字母print (Str4.isspace ())   #是否全为空白字符print (Str3.islower ())   #是否全为小写print ( Str3.isupper ())   #是否全为大写print (Str3.istitle ())   #是否为首字母大写运行结果:hello,world        python is a dynamic language        python is a dynamic language abcd efg,this is a  TESTABCD EFG,THIS IS A TESTABCD EFG,THIS IS A TESTABCD EFG, This is a testabcd efg,this is a testabcd efg,this is a  test-117172ybcd efg,this is y testpython is dynamic language Python is a dynamic language ============== Python is a dynamic language falsetruefalsefalsetruefalsefalsefalse


This article from "Ding classmate 1990" blog, declined reprint!

Python string manipulation

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.