0% found this document useful (0 votes)
2K views15 pages

Art Integrated Project Computer Science

A string is a set of characters enclosed in quotation marks, common string operations include concatenation, replication, membership checks, and comparisons, and strings can be indexed, sliced, and traversed to access individual characters or substrings.

Uploaded by

payal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views15 pages

Art Integrated Project Computer Science

A string is a set of characters enclosed in quotation marks, common string operations include concatenation, replication, membership checks, and comparisons, and strings can be indexed, sliced, and traversed to access individual characters or substrings.

Uploaded by

payal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

String data type

• • Art integrated project


Art integrated project
• • Computer science
Computer science
*Examples of strings
* name="my name is abc"
#string enclosed within
double quotation marks("")
* nm='hello how are you?'
* WHAT IS A #string enclosed within single
STRING? quotation marks('')
A string is a set of characters * A='''python is a programming
enclosed within any type of
quotation marks(single , double
language , python is a high
or even triple quotation marks) level language''' #string
enclosed within triple
quotation marks(multiline
string)
• Example of a
multiline string

“““

** Types
Types of
of strings
strings
Pineapple orange pear

• Multi line strings:


• The strings which are created
by using a triple quotes or by
adding a backslash at the end
of a normal single /double
quoted string.
Apple avocado lemon
Example of a single
line string:


* 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.

>>> name="samsung“ #string


>>> print(len(name)) #using the len() function to
determine the size of the string
7
>>> A="A is a alphabet"
>>> print(len(A)) #spaces are also
considered while counting the size of the string
15
>>> B="python is a very easy language to learn"
>>> print(len(B))
39
name="television"
>>> for i in name:
print(i) #string
traversing

* 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:

1.) concatenation operator



+
Panda wolf
” dinosaur

=

Panda wolf
2.) replication operators

Panda wolf


*
=
2
“ ”

Panda wolf Panda wolf


* Example:
* A="python was
developed by Guido
Van Rossum in
february 1991"
**2.)membership
2.)membership * >>> "python" in A
operators
operators * True
1.) in : this operator * >>> "Gui" in A
1.) in : this operator
returns true if a
returns true
character or aif a * True
character or aof a string)
substring(part * >>> "computer" in A
issubstring(part of a string)
present in a string else
is present in
it returns falsea string else * False
it returns false
* Example:
* B="python is a
programming language"
* >>> "python" not in B
**2).2).Membership
Membership * False
operator
operator * >>> "language" not in B
2.) not in : this operator
* False
returns true when the * >>> "room" not in B
character or the
substring(part of a string)is * True
not present inside the
string. * >>> "the" not in B
* True
* examples:
* a="good morning"
* >>> b="python” # strings are
compared on the basis of their ASCII
characters code
* >>> a==b
* 3.) comparison * False
operators * >>> a!=b
we can apply comparison
* True

we can apply comparison
• operators(==,<,>,! * a<b
operators(==,<,>,!
=,<=,>=,Etc.) on the strings.
=,<=,>=,Etc.) on the strings. * True
• Comparison is done
Comparison
• character is done
by character * >>> b>=a
character by character * True
• Note: strings are compared
• onNote: strings
the basis are ASCII
of their compared * >>> b<a
on the basis
character codesof.their ASCII
character codes. * False
• Made by:
• Name= payal

• Class= 11th-B

• Roll no.= 07

• Subject= computer
science

You might also like