Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 28, 2021 05:15 am GMT

Learning Python-Basic course: Day 23, String Methods Part-2

Today we cover more about string functions.

String functions are inbuilt methods to modify and change strings. In case you missed yesterday's part, click here.

String functions for GUI.

  • isalpha()- to check if all characters are alphabets.
  • isalnum()- to check if all characters are alphanumeric.
  • isdigit()- to check if all characters are digits.
  • islower()- to check if all characters are lower case.
  • isspace()- to check if all characters are blank spaces.
  • istitle()- to check if all characters follow title rules.
  • isupper()-to check if all characters are upper case.

The methods above are useful especially when we deal with GUI. For example, when we want the users to enter only alphanumeric values for passwords, alphabets for names and only digits for pin-codes These are useful to prevent errors in complex operations like OOP, GUI or file reading which we will cover in the next module.

txt=" Computer Academy"print(txt)#Returns True if all characters in the string are alphabetsprint("1.", "isalpha()", txt.isalpha())#Returns True if all characters in the string are only alphanumerictxt="Level1"print("
",txt)print("2.", "isalnum()", txt.isalnum()) #Returns True if all characters in the string are digitstxt="1154"print("
",txt)print("3.", "isdigit()", txt.isdigit()) #Returns True if all characters in the string are lower casetxt="computer academy"print("
",txt)print("4.", "islower()", txt.islower()) #Returns True if all characters in the string are whitespacestxt="computer academy"print("
",txt)print("5.", "isspace()", txt.isspace()) #Returns True if the string follows the rules of a titletxt="Computer Academy"print("
",txt)print("6.", "istitle()", txt.istitle()) #Returns True if all characters in the string are upper casetxt="PYTHON PROGRAMMING"print("
",txt)print("7.", "isupper()", txt.isupper())

Output-

 Computer Academy1.  isalpha()    False Level12.  isalnum()    True 11543.  isdigit()    True computer academy4.  islower()    True computer academy5.  isspace()    False Computer Academy6.  istitle()    True PYTHON PROGRAMMING7.  isupper()    True

Exercise-

Write a program to check if a string is alphabetic, numeric or alphanumeric or none.. answer in the Learning Python repo

So friends that's all for this part. Hope you all are enjoying. Please let me know in the comment section if you liked it or not. And don't forget to like the post if you did. I am open to any suggestions or doubts. Just post in the comments below or gmail me.
Thank you for being so patient.


Original Link: https://dev.to/aatmaj/day-23-fi9

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To