Part II – Creation and use of strings

--Originally published at TC101 – Peaz Cooper

Well well well! First of all! Ask yourself the following questions:

What is a string? How can you create it? Am I Pinnochio? Together we will learn the answers to these awesome and mind-blowing questions!


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.

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

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.

#!/usr/bin/python

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

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

(WIKI)

If you follow these steps you’ll be coding like a bawse in no time!!!

#PeazCooperOut #TC101