Introduction To Strings in Python
Well many of us are familiar with programming languages like C, C++, etc. and everyone will have an answer like “String is a collection or array of characters.”
Similarly, In Python language, string refers to an immutable sequence of characters. Creating Strings is the simplest and easy to use in Python. To create a string in Python, we simply enclose a text in single as well as double quotes. Python treats both single and double quotes statements the same. Triple quotes are used usually when we want to write multi-line sentences.
Accessing characters in a python string
If we want to access a character from a string we need to know its position in the string.
Some string functions in python
- capitalize( ): It converts the first character to the upper case.
- title( ): It converts the first character of each word to upper case
- casefold( ): Converts string into lower case
- count( ): It returns the number of times a specified value occurs in a string
- find( ): It finds the first occurrence of the specified value.
- replace( ): It replaces a specified phrase with another specified phrase.
- swapcase( ): Swaps cases, the lower case becomes the upper case and vice versa
- join( ): It takes all items in an iterable and joins them into one string.
Some examples of string functions :