By | August 26, 2020

In this article, we are telling you about String Formatting in Python, String Slicing in Python, and String Indexing in Python. Why and when all this is used is being told to you here.

We have given you articles on python in the past, before learning this, you must read our articles once before going about string formatting in python, string slicing in python and string indexing in python.

We have told you all this before, you can read that article if you do not understand how and why string is used in python, in such a way you can string indexing in python, string formatting in python and string slicing in can’t understand python.

String Formatting , String Indexing and String Slicing in Python ?

First of all, you must know why string indexing, string formatting and string slicing are used in python, plus you should also know what happens by using all of this

Just like we use string indexing when we have to print a single alphabet from a word like say our website name is freelearningtech, if you want to print l from it then string indexing is used.

We use string formatting to print a string in a simple way as you have been told earlier, we use str to print the number, in such a way we need to use str by using string formatting in python. Does not occur

We use string slicing to print half a word or some alphabets from a word, like our website name is freelearningtech, in such a way if we want to print freelearn then we use string slicing in python.

Also Read

How to use int function python ?

User Input python and String concatenation ?

String Formatting in Python

First of all, we are telling you practically about String formatting in python, to understand all this, we have made a simple program, here you can see the program in the image.

As you can see in the image, we have told you in the earlier program that in order to print a number, we have to use double quotes or str, in such a way you can do all this by using String formatting in python.

As we have used curly brackets, you can see in the image we have given you python3 and python3.6. You can see in the image about how String formatting is used in the program.

Like we have in python3. .format has to be used here, curly brackets are blank. We are used in python3.6 then You can declare the variable in curly brackets using f, you can also see the output, you get the same.

Similarly, if you want to print from plus or minus even from the number, then you can do this using String formatting as you can see in the image, in this way String formatting is used in python.

String Indexing in Python

Before understanding about String slicing in python, you should know about String Indexing in python as you have been told String Indexing is used to print a single character from a word.

Here all the characters are given a position as you can see in the image, in this way all the characters of any word are given the position, it is printed according to the position.

Just like here we have printed a character with 6 position, in the same way any character is printed here starting from 0 as in freelearn word f position is considered as 0.

String Slicing in Python

Just like if you have to give a position in reverse, then we have to start from -1 as you can see in the image. We have printed a character with -6 position, in this way String Indexing in python is used.

String Slicing in Python

Let us now know about String slicing in python as you have been told when we have to print some characters from a word, to do this we use String slicing in python.

Here we have to use the start argument as well as the stop argument, here one thing you have to keep in mind is 1 minus the position of the stop argument, you get print in the output.

String Slicing in Python

Like suppose a word is freelearn, in such a case the position of the word is up to 0-8 here if you want to print the lea then you have to give 4 in the start argument and 7 in the stop argument as you can see in the image.

Here the position is always declared in place holder as you can see in the image brackets have been used. These brackets in string slicing in python are called place holder.

Here if you do not declare the start argument in such a way, bydefault is from the starting 0 position as you can see in the image.In the same way, if you do not declare the stop argument, the output is reached till the last position.

String Slicing in Python

Here if you do not declare both the start argument and the stop argument, the complete word is printed, here you can understand that all the position characters are printed and found in the output, in this way String slicing in python is used.

String Slicing in Python

The Conclusion

I hope that you have come to know about String Slicing in python, String formatting in python and String Indexing in python, we have told you here by practically using all of them.

Before using it all, you must learn to use String once, we have told you about it earlier, you must read that article only then you can understand the use of String Slicing in python or String formatting in python.

Here if you have any kind of problem in using it all, in such a way, you can ask in a comment, we will help you completely, if you want, you can also ask us by contacting us.

You can also find articles of ethical Hacking here, if you want, you can also read them like facebook Hacking, Whatsapp hack, IOT Hacking and much more, you get to learn here, subscribe to our blog for new articles

Sharing is Caring

Thankyou

Leave a Reply

Your email address will not be published. Required fields are marked *