What is String in Python?
Strings are contiguous series of characters enclosed in single or double quotes. Python doesn't have
any separate data type for characters so they are represented as a single character string.
For eg.
>>> s_name = "Amit" # s_name is a variable storing a string.
>>>s = 'a' #String can also be enclosed in single quotes
How to Create Strings in Python?
Creating strings: To create string enclose the character or sequence of character in Single or Double
Quotes like shown below
>>> s_name = "Amit" #String enclosed in double quotes
>>>s = 'a' # String enclosed in Single Quotes
We can also use str() function to create string:
N = str () # This function will create an empty string
name = str(1234) # This will create a variable name which store a string "1234"
If we execute the following code:
>>>print(name)
Output will come
1234
Practice Questions
Q1. Write a program to count the frequency of a character in a string.
str=input("Enter any String")
ch=input("Enter the character")
print([Link](ch))
Q2. Write a program to accept a string and return a string having first letter of each word in capital.
str=input("Enter any String")
print([Link]())
Q3. Write a program to accept a string and display the following:
1. Number of uppercase characters
2. Numbers of lowercase characters
3. Total number of alphabets
4. Number of digits