Strings:
v Strings
v String slices
v Immutability
v String functions and methods
v String module
v String is defined as sequence of characters
represented in quotation marks (either single quotes ( ‘ ) or double quotes (
“ ).
v An individual character in a string is
accessed using a index.
v The index should always be an integer
(positive or negative).
v A index starts from 0 to n-1.
v Strings are immutable i.e. the contents of the
string cannot be changed after it is created.
v Python will get the input at run time by
default as a string.
v Python does not support character data type. A
string of size 1 can be treated as characters.
1. single
quotes (' ')
2.
double
quotes (" ")
3.
triple quotes(“””
“”””)
1.
Indexing
2.
Slicing
3.
Concatenation
4.
Repetitions
5.
Member ship
v
A
part of a string is called string slices.
v
The process of extracting a sub string from a
string is called slicing.
v
Python
strings are “immutable” as they cannot be changed after they are created.
v
Therefore
[ ] operator cannot be used on the left side of an assignment.
A method is a function that “belongs to” an object.
Stringname.method()
a=”happy
birthday”
here, a is the
string name.
v A module is a file containing Python
definitions, functions, statements.
v Standard library of Python is extended as
modules.
v To use these modules in a program, programmer
needs to import the module.
v Once we import a module, we can reference or
use to any of its functions or variables in our code.
v There is large number of standard modules also
available in python.
v Standard modules can be imported the same way
as we import our user-defined modules.
import
module_name
import string
print(string.punctuation)
print(string.digits)
print(string.printable)
print(string.capwords("happ
y
birthday"))
print(string.hexdigits)
print(string.octdigits)
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
0123456789
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJ
KLMNOPQRSTUVWXYZ!"#$%&'()*+,-
./:;<=>?@[\]^_`{|}~
Happy Birthday
0123456789abcdefABCDEF
01234567
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.