Book Image

Python Fundamentals

By : Ryan Marvin, Mark Nganga, Amos Omondi
Book Image

Python Fundamentals

By: Ryan Marvin, Mark Nganga, Amos Omondi

Overview of this book

After a brief history of Python and key differences between Python 2 and Python 3, you'll understand how Python has been used in applications such as YouTube and Google App Engine. As you work with the language, you'll learn about control statements, delve into controlling program flow and gradually work on more structured programs via functions. As you settle into the Python ecosystem, you'll learn about data structures and study ways to correctly store and represent information. By working through specific examples, you'll learn how Python implements object-oriented programming (OOP) concepts of abstraction, encapsulation of data, inheritance, and polymorphism. You'll be given an overview of how imports, modules, and packages work in Python, how you can handle errors to prevent apps from crashing, as well as file manipulation. By the end of this book, you'll have built up an impressive portfolio of projects and armed yourself with the skills you need to tackle Python projects in the real world.
Table of Contents (12 chapters)
Python Fundamentals
Preface

Strings


In this section, we will look at strings in detail.

String Operations and Methods

As we mentioned in the previous chapter, strings are a sequence of characters. The characters in a string can be enclosed in either single (') or double (") quotes. This does not make a difference. A string enclosed in single quotes is completely identical to one enclosed in double quotes:

>>> "a string"
'a string'
>>> 'foobar'
'foobar'
>>>

A double-quoted string can contain single quotes:

>>> "Susan's"
"Susan's"
>>>

A single-quoted string can also contain double quotes:

>>> '"Help!", he exclaimed.'
'"Help!", he exclaimed.'
>>>

You can also build a multiline string by enclosing the characters in triple quotes (''' or """):

>>> s = """A multiline
string"""
>>> print(s)
A multiline
string
>>> s2 = '''Also a
multiline string
'''
>>> print(s2)
Also a
multiline string
>>>

Also, as you saw in the first chapter...