String Datatype

String Datatype

Any sequence of characters within either single quotes or double quotes is considered as a String.

The most commonly used object in any project and in any programming language is String only. Hence we should aware complete information about String datatype.

Syntax

s = 'Waytoeasylearn' 
s = "Waytoeasylearn"

Note

In most of other languages like C, C++, Java, a single character with in single quotes is treated as char data type value. But in Python we are not having char data type. Hence it is treated as String only.

E.g

>>> ch = 'a' 
>>> type(ch) 
<class 'str'>

We can define multi-line String literals by using triple single or double quotes.

E.g

>>> s = '''Welcome 
To
Waytoeasylearn'''

We can also use triple quotes to use single quotes or double quotes as symbol inside String literal.

s = 'This is ' single quote symbol' ==> Invalid 
s = 'This is \' single quote symbol' ==> Valid 
s = "This is ' single quote symbol" ==> Valid 
s = 'The "Python Tutorial" by 'Waytoeasylearn' is very helpful' ==> Invalid 
s = "The "Python Tutorial" by 'Waytoeasylearn' is very helpful" ==> Invalid 
s = 'The \"Python Tutorial\" by \'Waytoeasylearn\' is very helpful' ==> Valid 8
s = '''The "Python Tutorial" by 'Waytoeasylearn' is very helpful''' ==> Valid

String Datatype


Scroll to top