Home arrow Python arrow Python: Stringing You Along

Python: Stringing You Along

If you have ever programmed before, or are a ninety-year-old lady, or a cat, then you know how useful strings are. If you have been reading these articles, you will know that a string is a character, a sentence, a paragraph, a book, etc. If you haven't been reading these articles, then you're missing an important part of your education as a programmer. Don't keep yourself in the dark; start reading!

TABLE OF CONTENTS:
  1. Python: Stringing You Along
  2. Making Text Appear Exactly As You Typed It
  3. Other Ways to Span Text
  4. String Operators
By: James Payne
Rating: starstarstarstarstar / 5
January 28, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In this epic article we will cover the various ways to manipulate string objects in Python. These range from sorting and indexing to some of the built-in string methods. So put down those knitting tools, kick that cat across the room like a football, and let's be like Olivia Newton-John (i.e., let's get physical).

The Basics

Here we are going to cover some of the basics of strings. If you need a refresher on them, you can read along. Or, if you are a string writing pro, feel free to skip over this section, or read it and get real bored and send me hate mail. Whichever you choose is fine.

Printing a string


#!/usr/local/bin/python

print "Here are some samples of basic strings:"

print " "

print "Now you know and knowing is half the battle"

print "A"

print "9"

print "%#$@!"

print "It was the best of times, it was the worst of times,"

print "It was the age of wisdom, it was the age of foolishness"

print "It was the epoch of belief, it was the epoch of incredulity"

print "It was the season of Light, it was the season of Darkness"

print "This quote goes on forever..."

Storing Strings in Variables and Printing Them


#!/usr/local/bin/python

apple = "Fudgebuckets"

sentence="Look at this! It's a sentence! No wait...it's two sentences!"

print apple

print sentence

Printing Quoted Text


#!/usr/local/bin/python

print "And he said to me, 'I pity the fool!' "

print 'And I quote: "Quit yo jibba-jabba!"'

print " "

print "Notice that it is best to use single quotes when you want to do double quotes"

print "And double quotes when you want to do single quotes"



 
 
>>> More Python Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: