String in Python

  What is String in Python?



What is Strings?
Strings are used in Python to record text information, such as names. Strings in Python are actually a sequence, which basically means Python keeps track of every element in the string as a sequence. For example, Python understands the string "hello' to be a sequence of letters in a specific order. This means we will be able to use indexing to grab particular letters (like the first letter, or the last letter).
let's see some examples to understand what is it:-

What is string Indexing?
In Python, we use brackets [] after an object to call its index. We should also note that indexing starts at 0 for Python. Let's create a new object called and then walk through a few examples of indexing.

What is slicing?

We can use a  [:]  to perform slicing which grabs everything up to a designated point.

for  [2:]   Grab everything past the first term all the way to the length of string

for  [:4]   Grab everything up to the 4th index

for  [ : ]    Grab everything

for [:: 2]  Grab everything but go in step sizes of 2 ( that means jump 2 in forwarding)

for [:: -1 ]  We can use this to print a  string backward let's understand with examples on Jupiter notebook


String Properties :

It's important to note that strings have an important property known as immutability. This means that once a string is created, the elements within it can not be changed or replaced.


String Methods :

Objects in Python usually have built-in methods. These methods are functions inside the object (we will learn about these in much more depth later) that can perform actions or commands on the object itself.

We call methods with a period and then the method name. Methods are in the form:>>> object.method(parameters)

Where parameters are extra arguments we can pass into the method are given below let's have example one by one 

string.upper()  to convert string in  upper case 

string.lower()  to convert  string in  lower  case 

string.split()    split a string by blank space


for more details, you simply check out the documentation https://www.python.org/doc/ and for any query just comment in the box so that I solve your queries as soon as possible.

Comments