Art Integrated Project Computer Science
Art Integrated Project Computer Science
“““
** Types
Types of
of strings
strings
Pineapple orange pear
“
* Single line string
• Single line string is a
string that is created by
enclosing the string in
double or single quotes .
”
• they must terminate on
the same line.
• Size of a string
• The len() function of python is used to determine
the size of a string
• Size of a string is the count of the total no. of
characters present in the string.
* Individual characters of a t
string can be accessed e
through the unique index l
value of each character .By
e
using the index values we
can traverse a string v
character by character. i
s
* Traversing refers to iterating
through the elements of the i
string , one character at a o
time. n
*Traversing a string
* As we know slice means “part of a string”, so
slicing is a process of extracting a part of a string .
* Examples:
*str1="computer science“ #output given according to the indexing
*>>> print(str1[1:4])
*omp
*>>> print(str1[4:7])
*ute
*>>> print(str1[7:8])
*r
*>>> print(str1[9:5]) #no output
String slicing
* String operators are used to do the
manipulation on the string .These are of three
types:
* 1.)Basic operators:
* A). concatenation(+) B).replication(*)
* 2.)Membership operators:
* A). In B). Not in
* 3.)Comparison operators(==,<,>,!
=,<=,>=0
*String operators
2.)replication
1.)concatenation 2.)replication
1.)concatenation operator(*)
operator(+) operator(*)
operator(+)
* The
The
main purpose of
main purpose
* This operator is used
*this operator is to of to duplicate or repeat
this operator
combine or joinistwo
to a string ‘n’ times
combine or join two
strings.
strings. * The operands can be a
* Note : we can not string and a number or
Note: we cannumbers
*combine(add) not both numbers.
combine(add)
with numbers
a string using this
with a
operator.string
operator.
* Symbol= +
using this
* Symbol= *
* Symbol= +
*Basic operators
Examples of the basic operators:
“
“
+
Panda wolf
” dinosaur
”
=
Panda wolf
2.) replication operators
Panda wolf
“
”
*
=
2
“ ”
• Roll no.= 07
• Subject= computer
science