AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

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
x = "My page with Python Programming"
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:
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:
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:
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:
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):
a = "Get the character"
print(a[4])
print(a[8])
print(a[9])
Output:
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":
for a in "sentence":
print(a)
Output:
s
e
n
t
e
n
c
e

String Length


To get the length of a string, use the len() function.

Example:
x = "Techniques to Create string"
print(len(x))
Output:
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
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.