Python Basic String Operations
kodingwindow@kw:~$ python3 ... >>> "Kodingwindow" 'Kodingwindow' >>> 'Kodingwindow' 'Kodingwindow' >>> print("Kodingwindow") Kodingwindow >>> print("\'Kodingwindow\'") 'Kodingwindow' >>> print('\"Kodingwindow\"') "Kodingwindow" >>> print("Koding\nwindow") Koding window >>> kw="Kodingwindow" >>> kw 'Kodingwindow' >>> len(kw) 12 >>> del kw >>> kwTraceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'kw' is not defined
Strings Concatenation
>>> s1="Koding" >>> s2="window" >>> s1+s1 'KodingKoding' >>> s1+s2 'Kodingwindow' >>> s1*5 'KodingKodingKodingKodingKoding' >>> s1,s2 ('Koding', 'window')
Escape Characters
>>> kw="Koding\nwindow" >>> kw 'Koding\nwindow' >>> kw="Koding\nwindow" >>> print(kw) Koding window >>> kw=r"Koding\nwindow" >>> print(kw) Koding\nwindow >>> print('\"Kodingwindow\"') "Kodingwindow" >>> kw="Koding\twindow" >>> print(kw) Koding window
What Next?
Python Strings Comparison
Python String Slicing
Python to check the given string is alphanumeric
Advertisement