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 :-

  1. Single quote string :- ‘Codeupon’
  2. Double quote string :- “Codeupon”
  3. 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

str = "codeupon"
print(str[0:5])
Python

Output :-

codeu
Markup

Example #2 :- Slicing string with skip values

str = "codeupon"
 
print(str[0:5:2])
Python

Output :-

cdu
Python

Example #3 :- Reversing a string

str = "codeupon"
print(str[::-1])
Python

Output :-

nopuedoc 
Python

String Functions

Some of the mostly used functions to perform operation on or manipulate strings are :-

  1. len () Function :- This function is used to find the length of the string.

Example :-

word = "codeupon"
print(len(word))
Python

Output :-

7
Markup

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 :-

str = "Good bye"
print(str.end("bye"))
Python

Output :-

True
Markup

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 :-

str = "Goodbye"
print(str.find("bye"))
Python

Output :-

4
Markup

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

Popular posts from this blog

⚠️How to create a virus in termux app ?

List in Python

How To Install Metasploit In Termux App ?