Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Python Strings

Rating
-
Sold
1
Pages
49
Uploaded on
19-10-2021
Written in
2021/2022

This Document consists of Python string programming notes.

Institution
Course

Content preview

UNIT-3

Strings revisited

We know that a String is a sequence of characters. Strings in Python are immutable. You can’t
change a string in place, but you can copy parts of strings to another string to get the same effect.

Python string is created by enclosing characters in either single quotes or double quotes, as
demonstrated in the following:

>>> ‘Python is fun’
‘Python is fun’

>>> “Python is easy”
‘Python is easy’

The interactive interpreter echoes strings with a single quote, but all are treated exactly the same
by Python.

You must be wondering why have two kinds of quote characters?

Try this program ‘Strings_demo.py‘ and see the ouput, you might figure out the reason behind
using two kinds of quotes.

,In case you couldn’t notice the reason is so that you can create strings containing quote
characters. You can have single quotes inside double-quoted strings, or double quotes inside
single-quoted strings. The output for Strings_demo.py would further clarify –




Even three single quotes (”’) or three double quotes (“””) can also be used. Their most common
use is to create multi-line strings. Try this on your editor and see the output-

note = ”’You should know that,
… Python is a snake;
… But this programming language,
… has nothing to do with the snake as”
… it is named after Monty Python.”’

print (note)

,If you wish you can create an empty string as well. The following program demonstrates it’s
usage-




See the output: Total users: 150

So want to build a string from other strings, and you need to start with a blank string. Also you
may have noticed that you can convert other Python data types to strings by using the str()
function, as we did in our previous program (message += str(users)).

Escape sequences

By preceding a character with a backslash (\), you give it a special meaning.

, 1. The most common escape sequence is \n, which means to begin a new line. With this you can
create multi-line strings from a one-line string.

Example: print(“Languages: \n Python \n C \n Java”)




2. escape sequence \t (tab) used to align text

Example:

Written for

Institution
Course

Document information

Uploaded on
October 19, 2021
Number of pages
49
Written in
2021/2022
Type
SUMMARY

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
kishoreragav179

Get to know the seller

Seller avatar
kishoreragav179 Asan Memorial College of Arts and Science
Follow You need to be logged in order to follow users or courses
Sold
1
Member since
4 year
Number of followers
1
Documents
1
Last sold
4 year ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions