Python String Data Type

 

Example


String is one the datatype for python.

String literals in python are surrounded by either single quotation marks, or double quotation marks.

'hello' is the same as "hello".

Python Support positive as well as Negative Indexing


var = "Hello" is same as var = 'Hello'

var = "I Love Python"

# Multiline String

var = '''

I Love Python

I Love Django ''''


''' ''' ---> this one is known as docstring in python


This is How Python store a string, see the below Image



a = "Hello, World!"
print(a[0])

Output: H


a = "Hello, World!"
print(a[1])

Output: e


a = "Hello, World!"
print(a[-1])

Output: !


a = "Hello, World!"
print(a[-2])

Output: d


# Python Slice Concept
# Remember it touches Lower bound not Does not touch the upper bound.

a = "Hello, World!"
print(a[0: 3])

Output: Hel


a = "Hello, World!"
print(a[2: 3])

Output: l


a = "Hello, World!"
print(a[-4: -1])

Output: rld


a = "Hello, World!"
print(a[: : -1])

Output: !dlroW ,olleH


txt = "The rain in Spain stays mainly in the plain"
x = "ain" in txt
print(x)

Output: True


a = "Kuntal"
b = "Samanta"
c = a + b
print(c)

Output: Kuntal Samanta




Enjoy Edge-cutting Technology 😉

Get Help

Comments

Popular posts from this blog

How To Create .ENV File in Python

Create a Large file for Test Data Processing using Python

How to solve the Liner Equation using Python