Posts

string methods

Image
  Extended Slicing and String Methods Extended Slicing Syntax: variable[start_index:end_index:step] Step determines the increment between each index for slicing. Code 1 2 3 a = "Waterfall" part = a [ 1 : 6 : 3 ] print ( part ) PYTHON Output ar Methods Python has a set of built-in reusable utilities. They simplify the most commonly performed operations are: String Methods isdigit() strip() lower() upper() startswith() endswith() replace()  and more... Isdigit Syntax: str_var.isdigit() Gives True if all the characters are digits. Otherwise, False Code 1 2 is_digit = "4748" . isdigit ( ) print ( is_digit ) PYTHON Output True Strip Syntax: str_var.strip() Removes all the leading and trailing spaces from a string. Code 1 2 3 mobile = " 9876543210 " mobile = mobile . strip ( ) print ( mobile ) PYTHON Output 9876543210 Strip - Specific characters Syntax: str_var.strip(chars) We can also specify characters that need to be removed. Co...