Strings & Textual Data

In this Python Beginner Tutorial, we will begin learning about the Textual Data Type. Strings can be worked with textual data in Python. We will be applying different ways to format strings, and also doing some major string methods/functions. Lets start Donating Python Bytes.

Strings are amongst the most popular types in Python. We can create them simply by enclosing characters in quotes. Python treats single quotes the same as double quotes. Creating strings is as simple as assigning a value to a variable. For Example:

var1 = 'Hello World!'
var2 = "Python Programming"

Accessing Values in Strings

Python does not support a character type; these are treated as strings of length one, thus also considered a substring.

To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring. For example:

#!/usr/bin/python

var1 = 'Hello World!'
var2 = "Python Programming"

print "var1[0]: ", var1[0]
print "var2[1:5]: ", var2[1:5]

When the above code is executed, it produces the following result:

var1[0]:  H
var2[1:5]:  ytho

Updating Strings

ou can “update” an existing string by (re)assigning a variable to another string. The new value can be related to its previous value or to a completely different string altogether. For example:

#!/usr/bin/python

var1 = 'Hello World!'
print "Updated String :- ", var1[:6] + 'ByteDonor'

When the above code is executed, it produces the following result:

Updated String :-  Hello ByteDonor

Escape Characters

Following table is a list of escape or non-printable characters that can be represented with backslash notation.
An escape character gets interpreted; in a single quoted as well as double quoted strings.

PyCharm Setup: https://www.jetbrains.com/pycharm/
Sublime Text Setup: https://www.sublimetext.com/3
Atom Setup Video: https://atom.io/

Beginners Guide - Download