CS Art Integrated Progect

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

STRINGS

Acknowledgement
Submitted by : shresth saini
Class : 11-A
Roll No : 11110
Topic : Strings
Submitted to : Namrata Mam
STRINGS IN PYTHON
● In python, a consecutive sequence of characters, which are enclosed by single (‘’) or
double (“”) quotes is known as strings.

● Strings are immutable and hence you cannot change the individual letters of string
using assignment operators.
ACCESSING CHARACTERS IN A STRING
● Strings in python are stored as individual characters i.e. indexed wise. The index by default
starts with 0.

str=

● So, here ‘H’ will be represented by str[0] or str[-11], ‘e’ will be represented by either str[1] or
str[-10] and so on.
STRING OPERATORS
● Concatenation operator (+) : This operator concatenates two different strings.

● Repitition operator (*) : This operator requires two types of operands – a string and a number. It
replicates the given string.
● Membership operator: “in” & “not in” : Membership operator is used to searching whether
the specific character is part/member of a given input python string.
STRING SLICING

● String slicing operator “[]” : Characters from a specific index of the string can be accessed with
the string[index] operator. The index is interpreted as a positive index starting from 0 from the left
side and a negative index starting from -1 from the right side.
Syntax - string[start:end:step]
STRING METHODS AND BUILT IN FUNCTIONS
Method Discription
.
len() Returns the length of the string
capitalze() Converts the first character to upper case
split() Splits the string at the specified separator, and returns a list

replace() Returns a string where a specified value is replaced with a specified


value
find() Searches the string for a specified value and returns the position of
where it was found
index() Searches the string for a specified value and returns the position of
where it was found
Method Discription
isalpha() Returns True if all characters in the string are in the alphabet
isalnum() Returns True if all characters in the string are alphanumeric
isdigit() Returns True if all characters in the string are digits
title() Converts the first character of each word to upper case
count() Returns the number of times a specified value occurs in a string
lower() Converts a string into lower case
islower() Returns True if all characters in the string are lower case
upper() Converts a string into upper case
lstrip() Returns a left trim version of the string
rstrip() Returns a right trim version of the string
strip() Returns a trimmed version of the string
isspace() Returns True if all characters in the string are whitespaces
istitle() Returns True if the string follows the rules of a title
Method Discription
join() Converts the elements of an iterable into a string
swapcase() Swaps cases, lower case becomes upper case and vice versa
partition() Returns a tuple where the string is parted into three parts
startswith() Returns true if the string starts with the specified value
endswith() Returns true if the string ends with the specified value

You might also like