String is a sequence of characters defined using quotes. There are four different types of quotes available in Python for string representation. Since there is no separate character type in Python, any quotes can be used for any string object.
>>> a = 'Programink'
>>> b = "Programink"
>>> c = '''Programink'''
>>> d = """Programink"""
>>> a == b == c == d
Three pairs of quotes are generally used for multi-line string or docstring. Consistency in the use of quotes is very important in Python.
>>> a = 'It din't rain today' # incorrect
>>> a = "It didn't rain today" # correct
Properties Of Python Strings
String data type in Python has the below properties:
- String has a sequential index starting from 0 and -1.
>>> s = "Hello"
- String is case-sensitive but not quotes sensitive.
>>> 'a' == 'A'
>>> 'a' == "a"
- String supports concatenation and repetition.
>>> "a" + "b"
>>> "ha" * 4
- String is immutable and it cannot be changed.
>>> x = "hello"
>>> y = x.upper()
Python String Attributes
String type object in Python has below built-in attributes: