Brainstorming 06: Mastering Python String

 

Easy (10 questions):

  1. Write a Python program to count the number of vowels in a given string.

  2. Convert a string to uppercase and lowercase using built-in string methods.

  3. Write a Python program to check if a string is a palindrome.

  4. Extract the first 5 characters from a given string.

  5. Write a Python program to reverse a string.

  6. Find the length of a given string using a built-in function.

  7. Write a Python program to replace all occurrences of a specific character in a string with another character.

  8. Write a Python program to split a string into a list of words.

  9. Write a Python program to concatenate two strings.

  10. Write a Python program to count how many times a specific substring occurs in a given string.

Medium (6 questions):

  1. Write a Python program to count the occurrences of each character in a string.

    • Sample Input: "apple"
    • Sample Output: {'a': 1, 'p': 2, 'l': 1, 'e': 1}
  2. Given a string, write a Python program to remove all spaces and capitalize the first letter of each word.

    • Sample Input: "hello world python"
    • Sample Output: "HelloWorldPython"
  3. Write a Python program to find the longest word in a sentence.

    • Sample Input: "Python is fun and educational"
    • Sample Output: "educational"
  4. Write a Python program to check if a given string is a valid email address (use basic rules like containing "@" and ".").

  5. Write a Python program to swap the case of all characters in a string (lowercase to uppercase and vice versa).

  6. Given two strings, write a program to find all the characters they have in common.

    • Sample Input: "abcde", "cdefg"
    • Sample Output: ['c', 'd', 'e']

Hard (4 questions):

  1. Write a Python program to find the first non-repeating character in a string.

    • Sample Input: "swiss"
    • Sample Output: "w"
  2. Write a Python program to find all possible permutations of a string.

    • Sample Input: "abc"
    • Sample Output: ["abc", "acb", "bac", "bca", "cab", "cba"]
  3. Given a string containing numbers and letters, write a program to sum all the digits in the string.

    • Sample Input: "ab123cd45"
    • Sample Output: 15
  4. Write a Python program to check if two strings are anagrams of each other (contain the same characters in different order).

    • Sample Input: "listen", "silent"
    • Sample Output: True
Previous Post Next Post