banner ad

Learn Python Strings

| January 15, 2013 | 0 Comments
0 Flares 0 Flares ×

Strings in Python is some text in quotes. e.g.

>>> "hello, python"
'hello, python'
>>> 

Strings are the basic unit of text in python. You can use single or double quotes for text in Python! e.g.

>>> "This is a string by double quotes"
'This is a string by double quotes'
>>> 'This is a string by single quotes'
'This is a string by single quotes'
>>> 

Three double quotes are used for multiple lines.

>>> """This is
a string by
multiple lines"""
'This is\na string by\nmultiple lines'
>>> 

escape character:
\n newline \\ backslash
\t tab \’Single quote
\r enter \”double quotes

print
Converts the print statement to the print() function.
print([object, …][, sep=’ ‘][, end=’\n’][, file=sys.stdout])
Print object(s) to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no object is given, print() will just write end.

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Output buffering is determined by file. Use file.flush() to ensure, for instance, immediate appearance on a screen.

>>> print "I have %d %s" % (1, "apple")
I have 1 apple
Download PDF
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Reddit 0 StumbleUpon 0 0 Flares ×

Tags: ,

Category: Python Strings

About the Author ()

My name is John Link.I am 26 years old. My major is Computer science and technology. I am a junior programmer with Python.

Leave a Reply

Your email address will not be published. Required fields are marked *

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Reddit 0 StumbleUpon 0 0 Flares ×