STRING OPERATIONS ================== CHANGING OF A CASE OF THE STRINGS ================================== upper() ====== ==> an inbuilt method in python, used to convert the total given string into upper case string. Syntax: str_data.upper() lower() ===== ==> an inbuilt method in python, used to convert the given string into lower case string. Syntax: str_data.lower() swapcase() ======== an inbuilt method in python, used to convert a lower case string to upper case and upper case string to lower case Syntax: str_data.swapcase() title() ==== Title case ==> that every word of the same string should be start with capital letter. ex: python programming language title case ==> Python Programming Language title() is an inbuilt method in python, used to convert anycase string into title case. Syntax: str_data.title() capitalize() ======== capitalize ==> in the entire string (might be with more than one word) that only the first word should start with capital remaining all the characters in lower case Ex: Python programming language capitalize() is an inbuilt method used to convert any case string into capitalize case. Syntax: str_data.capitalize() str1 = "python" str2 = "Python" str3 = "PYTHON" str4 = "PYTHON programming LanGuage" str5 = "object orieneted programming language" str6 = "HIGH LEVEL PROGRAMMING LANGUAGE" # Before the case change print(str1) print(str2) print(str3) print() # After the case change to upper case print(str1.upper()) print(str2.upper()) print(str3.upper()) print() # After the case change to lower case print(str1.lower()) print(str2.lower()) print(str3.lower()) print() # After the case change to swap case print(str1.swapcase()) print(str2.swapcase()) print(str3.swapcase()) print(str4.swapcase()) print() # After the case change to title case print(str4.title()) print(str5.title()) print(str6.title()) print() # After the case change to Capitalize case print(str1.capitalize()) print(str2.capitalize()) print(str3.capitalize()) print(str4.capitalize()) print(str5.capitalize()) print(str6.capitalize()) ================================ Note: ==== Identifiers: variables classes objects methods etc. ==> to name any entity in program, identifiers are used. ==> identifiers with different case formats lower case, upper case, title case, capitalize, camel case camel case: Python programming language camel case ==> python Programming Language ==> In Python: the identifiers can be suggested to define with "came case" in real world. ====================================================== String Validation: ============= Application full name user name password mail : @gmail.com/@rediffmail.com etc. Job Portal social media: linkedin : url facebook : url endswith() ======== ==> an inbuilt method in python, used to check whether the given string data is ended with specified group of characters/string or not. Syntax: str_data.endswith("reference String") return: True/False (Boolean value) startswith() ======== ==> an inbuilt method in python, used to check whether the given string is start with the specified group of characters/string or not. Syntax: str_data.startswith("Reference_String") return: True/False mail = "ravivraoinfs@gmail.com" email = "ravivraoinfs@gmaill.com" url = "http://www.ashokit.com" result1 = mail.endswith("@gmail.com") result2 = email.endswith("@gmail.com") print(result1) print(result2) if url.startswith("https://"): print("The Given URL is Secure.") else: print("The Given URL is not Secure.") ======================================== CHECKING OF CHARACTERS OF THE STRINGS ======================================= isalnum() ======= al ==> alphabets num ==> numerals ==> an inbuilt method in python used to check whether the given string with: alphabets and numerals only or not. return: true/fasle Syntax: str_data.isalnum() ================================ isalpha() ======= ==> an inbuilt method used to check whether the given string with only alphabets or not. return: True/False Syntax: str_data.isalpha() ======================= isdigit() ====== ==> an inbuilt method used to check whether a string with only digits or not. Syntax: str_data.isdigit() ============================== islower() ======= ==> used to check whether the given string with only lower case or not. Syntax: str_data.islower() ========================== isupper() ======= ==> used to check whether the given string with only uppercase alphabets or not. Syntax: str_data.isupper() ================================= isspace() ====== ==> return True: if the string with only spaces False: if the string with otherthan spaces Syntax: str_data.isspace() user_name = "Ravi1234" un1 = "ravi" un2 = "1234" un3 = "ravi@1234" cn1 = "ravikumar" cn2 = "ravi kumar" cn3 = "ravi1234" pin1 = "1234" pin2 = "abcd" pin3 = "12ab" pwd1 = "ravi" pwd2 = "ravi123" pwd3 = "RAVI" pwd4 = "r1A2v3i4" d1 = "" d2 = " " d3 = " " d4 = "ravi kumar" d5 = " ravi " # isalnum() print(user_name.isalnum()) print(un1.isalnum()) print(un2.isalnum()) print(un3.isalnum()) print() # isalpha() print(cn1.isalpha()) print(cn2.isalpha()) print(cn3.isalpha()) print() #isdigit() print(pin1.isdigit()) print(pin2.isdigit()) print(pin3.isdigit()) print() #islower() print(pwd1.islower()) print(pwd2.islower()) print(pwd3.islower()) print(pwd4.islower()) print() #isupper() print(pwd1.isupper()) print(pwd2.isupper()) print(pwd3.isupper()) print(pwd4.isupper()) print() # isspace() print(d1.isspace()) print(d2.isspace()) print(d3.isspace()) print(d4.isspace()) print(d5.isspace())