position: fixed; top: auto !important; margin-left: 112px;

Python Strings

Python strings can be written within single qoutes '' or double qoutes "". To print the length of string you can use len() function of string. Python does not support char datatype.

# You can use single quotes for initializing string literals string1 = 'hello' # or can use double quotes also string2 = "world" # String length print(len(string1)) # String Concatenation using + operator print(string1 + ' ' + string2) # sprintf style string formatting print('%s %s %d' % (string1, string2, 30))

Various methods of Python strings

This example illustrates various methods of python strings. Each line in code has comments to illustrate methods use.

s = "codzify" # Capitalize a string print(s.capitalize()) # Convert a string to uppercase print(s.upper()) # Convert a string to lowercase print(s.lower()) # Right-justify a string, padding with spaces print(s.rjust(10)) # Center a string, padding with spaces print(s.center(10)) # Replace all instances of one substring with another print(s.replace('fy', 'ffyy')) # Strip leading and trailing whitespace print(' .com '.strip())

Previous Next Article


Largest collection of up-to-date tutorials to learn programming languages. We are focused on easy learning. Massive collection of interview questions one may need for preparation.

Social Profile


Copyright 2018. All rights reserved.