This document provides an overview of string methods in Python. It contains a table with 13 common string methods like isalpha(), isdigit(), lower(), upper(), lstrip(), rstrip(), and join(). Each method is described, and examples are given to demonstrate how to use the methods and the output. The document is from the Computer Science department of Krishna Public School and covers string basics as part of a Python chapter.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
46 views
COMPUTER SCIENCE-XII-CH1-String-p2
This document provides an overview of string methods in Python. It contains a table with 13 common string methods like isalpha(), isdigit(), lower(), upper(), lstrip(), rstrip(), and join(). Each method is described, and examples are given to demonstrate how to use the methods and the output. The document is from the Computer Science department of Krishna Public School and covers string basics as part of a Python chapter.
1 isalpha() Return true if the string Str.isalpha() >>>str=“PYHTON”
contains only letters, otherwise >>>str.isalpha() returns false. >>>str=“123” >>>str.isalpha() 2 isdigit() This method return true if Str.isdigit() >>>str=“PYHTON” string contains only digits, >>>str.isdigit() otherwise return false >>>str=“123” >>>str.isdigit() 3 lower() Convert all the uppercase Str.lower >>>str=“PYTHON” letters in the string o >>>str.lower() lowercase, >>>print(str) If letters already into lower, then return lower only 4 Islower() Return true if all letters in the Str.islower() >>>str=“PYTHON” string are in lower case >>>str.islower() >>>str=“python” >>>str.islower() Write the program into python idle, and write the output
Computer Science with PYTHON class XII Chaper-1:String 3
5 upper() Convert all the lowercase Str.upper() >>>str=“python”
letters in the string to >>>str.upper() upperrcase, >>>print(str) If letters already into lower, then return lower only 6 isupper() Return true if all letters in the Str.isupper() >>>str=“PYTHON” string are in lower case >>>str.isupper() >>>str=“python” >>>str.isupper() 7 lstrip() Return string after remove Str.lstrip() >>>str=“Hello” NO change, because there is no whitespace at left, so Or leading or specified character >>>str.lstrip() Hello itself an output lstrip(char) whitespace from left of string [lstrip- Left >>>str=“ Hello” Here, a whitespace before H, so it removed that and give Stip] >>>str.lstrip() output Hello Str.lstrip(‘’) >>>str=“Ghello” Here, G comes before h, so it remove that and outs rest >>>str.lstrip(“G”) part of string, so output will be hello IMPORANT: it removes from left most side, not from between of string 8 rstrip() Return string after remove Str.rstrip() Try all example of Or leading or specified character Or lstrip as rstrip rstrip(char) whitespace from right of stringComputer Str.rstrip(‘’) Science with PYTHON class XII Chaper-1:String 4 2. String – Built-in String Method Sr. Method Description Syntax Example Output
9 isspace() Return true if string Str.isspace() >>>str=“ ”
contains whitespace only >>>str.isspace() otherwise false >>>str=“a b” >>>str.isspace() 10 istitle() Return true is string is Str.istitle() >>>str=“Python Programmming” proper title cased, >>>str.istitle() otherwise return false >>>str=“PYTHON PROGRAMMING” >>>str.istitle() 11 join(sequence) Return a string by joining Str.join(sequence) >>>s=“hello” string separator defined >>>str=“-” with sequence >>>str.join(s) >>>str=“#” >>>str.join(s) 12 Swapcase() Return string after Str.swapcase() >>>str=“hello” converting case. If string is >>>str.swapcase() in uppercase it convert it >>>str=“PYTHON” into lower or vice-versa >>>str.swapcase() 13 partition Used as separator, used to Str.partition(separator) >>>str=“Computer+Science” split given string, it return >>>s=str.partition(“+”) tuple of spited string s tuple Computer Science with PYTHON class XII Chaper-1:String 5 Thankyou Computer Science Department (Krishna Public School, Koni, Bilaspur) Sujeet Tiwari Mr. Liju K John Mrs Rubeena Mirza Mrs Disha Dhupar
Computer Science with PYTHON class XII Chaper-1:String 6