What is String in Python ? | Types of String | Basic String Operations and Methods in Python

 What is String in Python?

  • A string in Python is a sequence of characters, like letters, numbers, and symbols, enclosed in quotes.
  • Strings are used to represent text.

Program :



Output :



Basic String Operations and Methods in Python:

1. Concatenation:

  • Combining two or more strings into one.

Program with Output :



2. Repetition:

  • Repeating a string multiple times.

Program with Output :


3. Indexing:

  • Accessing individual characters in a string using their index (starting from 0).

Program with Output :



4. Slicing:

  • Slicing extracts a portion of a string by specifying a range of indices.

Program with Output :



5.  .upper() Method:

  • Converts all characters in a string to uppercase.

Program with Output :



6.   .lower() Method:

  • Converts all characters in a string to lowercase.

Program with Output :




7.  .replace() Method:

  • Replaces occurrences of a substring with another substring.

Program with Output :



8.  .split() Method:

  • Splits a string into a list of substrings based on a delimiter.

Program with Output :


Post a Comment

0 Comments