String Data Type in Python

 A String is a sequence of characters enclosed within single quotes or double quotes 'hello' is the same as "hello". Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.

Assign String to a Variable

Assigning a string to a variable is done with the variable name followed by an equal sign and the string:

>>> a = "Hello"
     >>> print(a)

Multiline Strings

You can assign a multiline string to a variable by using three double quotes or three single quotes:

 

>>> a = """ My name is Abdul Rais;

Working as an assistant professor;

in Lords Institute of Engineering and Technology."""

>>> print(a)




String Length

To get the length of a string, use the len( ) function.

strA = "I am Online Smart Trainer"

print("The length of string : ",len(strA))

strB= "IamOnlineSmartTrainer"

print("The length of string: ",len(strB))





Comments

Search related post on google