String In Python
A string is a sequence if characters. It can be declared in python by using double quotes. String are immutable i.e, They can not be changed.
We can primary write string in three ways :-
- Single quote string :- ‘Codeupon’
- Double quote string :- “Codeupon”
- Triple quote string :- ”’Codeupon”’
String slicing
A string in python can be sliced for getting a part of the string.
Syntax :-
variable_name [start index : end index : gap/skip index]
Example #1 :- Slicing the string
Output :-
Example #2 :- Slicing string with skip values
Output :-
Example #3 :- Reversing a string
Output :-
String Functions
Some of the mostly used functions to perform operation on or manipulate strings are :-
- len () Function :- This function is used to find the length of the string.
Example :-
Output :-
2. string.endwith (“bye”) :- This function tells whether the string ends with the string “bye” or not. It return True or False on the basis of string present or not.
Example :-
Output :-
3. string.find(substring) :- This function is used to find the sub string in the given string. Its return the position of the sub string from the string.
Example :-
Output :-
There are soo many string function are in python if you want to explore more then go through this link https://www.w3schools.com/python/python_strings.asp
I hope you find this tutorial helpful. If you have query or suggestion please do a comment.
Thank You.
Comments
Post a Comment