0% found this document useful (0 votes)
2 views7 pages

Understanding Strings in Python

Strings in Python are sequences of characters enclosed in single or double quotes, with no separate data type for characters. They can be created by enclosing characters in quotes or using the str() function. The document also includes practice questions for string manipulation, such as counting character frequency and formatting strings.

Uploaded by

himarnair09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Understanding Strings in Python

Strings in Python are sequences of characters enclosed in single or double quotes, with no separate data type for characters. They can be created by enclosing characters in quotes or using the str() function. The document also includes practice questions for string manipulation, such as counting character frequency and formatting strings.

Uploaded by

himarnair09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like