Python Strings
Python Tutorial » Python Strings
In Python Strings are surrounded by single quotation marks or double quotation marks as:
'My Pithon page' is the same as "My Pithon page".
Example: Assign String to a Variable
Output:
My page with Python Programming
x = "My page with Python Programming"
print(x)
print(x)
Output:
My page with Python Programming
Multiline Strings
You can assign a multiline string to a variable by using three quotes:
Example: Multiline Strings, use three double quotes:
In Python, you have different ways
to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes
x = """In Python, you have different ways
to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes"""
print(x)
Output: to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes"""
print(x)
In Python, you have different ways
to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes
Example: Or three single quotes:
In Python, you have different ways
to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes
x = '''In Python, you have different ways
to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes'''
print(x)
Output: to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes'''
print(x)
In Python, you have different ways
to specify a multiline string.
You can have a string split across
multiple lines by enclosing it in triple quotes
Strings are Arrays - examples
Square brackets can be used to access elements of the string.
Example: Get the character at position 4, 8 and 9 (first character has the position 0):
t
c
h
a = "Get the character"
print(a[4])
print(a[8])
print(a[9])
Output:print(a[4])
print(a[8])
print(a[9])
t
c
h
Looping Through a String
we can loop through the characters in a string, with a for loop
Example: Loop through the letters in the word "sentence":
s
e
n
t
e
n
c
e
for a in "sentence":
print(a)
Output:print(a)
s
e
n
t
e
n
c
e
String Length
To get the length of a string, use the len() function.
Example:
27
x = "Techniques to Create string"
print(len(x))
Output:print(len(x))
27
python string methods, length, contains, formay, to int, split, replace, to bytes, concatenation, Python string format, Python int to string, Python string operations
Python Strings - python
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.