You are here: Home / Topics / Explain String in Python

Explain String in Python

Filed under: Python on 2022-08-08 15:42:31

String is a collection of characters, python provides simple and easy way to manage or manipulate the string. In Python, single character are also a string of length one and string in python are immutable.

String is Immutable :-
It means that at runtime we can not change the index value in the string like
s="mystring"
s[1]='a'

This will give an error

Program-

string1=""
string2="This is my string in python"
print(string1)
print(string2)
s1="Hello"+"world"
print(s1)
s1="Hello"*2
print(s1)
print(s1[0])
print(s1[0:3])
print(len(s1))

Output:-

This is my string in python
Hello world
HelloHello
H
Hel
10

# Here '+' operator in python have a capability to add all type of similar data type like we can add
int +int
float+ float
list+list
string+string
# And '*' is multiple string and number here then it repeat the string as per the number which is multiple.
# Len(string) computes the length of the string.


About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.