String in Python

Last updated Aug 08, 2021

String

The sequence of Unicode characters is known as String and string is always written in the single quotation or double quotation marks. A string is denoted by str. Strings are one of the most used data types in any programming language because most of the real-world data such as name, address, or any sequence which contains alphanumeric characters are mostly of type ‘String’. Basically, in English vocabulary, there is a total of 26 alphabets and the string contains all these alphabets and some other keys. String in python means a sentence, line, or a block of the paragraph. But unlike numbers, with string, we can perform many tasks like concatenation, slicing, etc. So the string is a vast concept and all your python basic and advanced programming depends on a string. 

Let's take a basic example of String in Python:-


 

a = "Hello Coders"

print(type(a)

 

As you can see we had printed the type of our data type which is of str type.

Unlike the above example, you can perform many tasks in python with the help of strings. And of the other functions which you all can perform with the help of strings is known as string slicing. Let's take a wide look at some of the examples of string slicing:-


 

mystr = "Python is an easy programming language"

print(mystr)

print(mystr[0])

print(mystr[0:15])

print(mystr[:])

print(mystr[::2])

print(mystr[::-2])

print(mystr.endswith("language"))

print(mystr.count('o'))

print(mystr.capitalize())

print(mystr.replace("is", "are"))

print(mystr.upper())

print(mystr.lower())

print(mystr.find("is"))

 

Python is an easy programming language
P
Python is an ea
Python is an easy programming language
Pto sa aypormiglnug
eaga nmagr sen inhy
True
2
Python is an easy programming language
Python are an easy programming language
PYTHON IS AN EASY PROGRAMMING LANGUAGE
python is an easy programming language
7

 

So from the above example, you can see that we can perform a large number of things using strings and you can use any function you want to. So string in python is so important as it creates a base in the Python programming language.

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

60 Views