0% found this document useful (0 votes)
51 views24 pages

Term1 Notes For Notebook - 033114

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

Term1 Notes For Notebook - 033114

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

Chapter 1

Computer System Overview

Components of computer
A computer system comprises of 5 basic components:-
i) Input unit:- Responsible for taking input from the user.
ii) Output Unit:- Responsible for generating result for the users.
iii) CPU:- Responsible for processing the data and instructions.
iv) Primary memory:- internal volatile memory where data and instructions are stored
during the processing.
v) Secondary memory:- External storage devices which provide permanent memory to the
computer system.

Computer Organization:-
It refers to the logical structure of a computer describing how its components are
connected together.
CPU
ALU Registers

Control Memory

BUS

Input Unit Output Storage Unit


Unit
1) Input Unit:- Responsible for taking input and converting it into Computer
understandable language i.e binary code. Some common input devices are keyboard,
scanner, microphone, mouse etc.

2) Output Unit:- This unit is formed by the output devices attached to the computer. The
output coming from the CPU is in the for m of electronic binary signals which needs
conversion in some form which can be easily understandable by human, so this
conversion is done by an Output devices. Some common output devices are monitors,
speakers, printers and so on.
3) CPU:- Central Processing Unit (CPU):- The CPU or processor is the unit which perform
most of the processing inside a computer. It processes all instructions received by
software running on the computer, and also by hardware components.
CPU is also known as Processor and consists of three units namely:-
i) Control unit ii) Arithmetic Logic Unit iii) Registers

3.1) Control Unit:-


Functions of this unit are:-
 Responsible for controlling the transfer of data and instructions among other
units of computer.
 Manage and co-ordinate all units of computer
 Obtain the instructions from the memory, interpret them and directs the
operation.
 Communicates with I/O devices for the transferring of data or result from
storage.
 It doesn’t process or store any data.

3.2) ALU:- It is a digital circuit inside the processor that handles arithmetic and logical
operations by loading data from input registers(temporary memory space).
3.3) Registers:- Registers or processors are small unit of memory. The CPU uses registers
to temporarily hold some important processing-information during the processing time.
CPU may stores some part of data or memory address or some instructions in registers.

Memory Units
Smallest memory of the computer system is Bits i.e 0 or 1
B
i
t
s
B
yt
es
(8
bi
ts
)
Kil
o
Byt
es(
KB
)
(10
24
byt
es)

Me
ga
Byt
es
(M
B)

(10
24
KB)

Gi
ga
By
tes
(G
B)
(1
02
4
M
B)
Te
rra
By
tes
(T
B)
(1
02
4
GB
)
Pe
ta
By
tes
(P
B)
(1
02
4
TB
)
Ex
a
By
te
(E
B)
(1
02
4
PB
)
Ze
tta
By
te(
ZB
)
(1
02
4
EB
)
Yo
tta
By
te(
YB
)
(1
02
4
ZB
)
ROM:-
 Performs read only operations
 Stores the data permanently in memory.
 It’s a non-volatile memory
 ROM’s are used in applications where information never need to be altered.

Some types of ROM’s are given below:-

1) PROM (Programmable ROM):- Also called OTP. In this type information is burnt
using special equipment called ROM Burner.

2) EPROM(Erasable PROM):- IN this type of ROM data can be erased number of


times as needed. An UV-EPROM can take upto 20 mins. to erase the EPROM
contents.
3) EEPROM(Electrically Erasable PROM):- In this type data erase electrically which ic
mush faster than EPROM. Also in this type selected data can be erased unlike UV-
EPROM which erases full data.

4) Flash EEPROM:- It is same as EEPROM but much faster than then EEPROM and
erase the full data not selected.

5) Mask ROM:- IN this type of ROM contents are programmed by the IC


manufacturer and its not an user programmable ROM.

Cache Memory:-
The cache memory is a high speed memory available inside CPU in order to speed up
access to data and instructions stored in RAM. If the data is found in cache, CPU does not
access memory and hence the process becomes fast.
When data is found in cache, it is called cache hit and the effectiveness of cache
memory is judged by its hit rate.

The System Bus


It is a n electronic pathway composed of connecting cables and that connects the major
components of a computer system. Through system bus, data and instructions are passed
among the computer system components.
 Data Bus:- Data carrying part of the system.
 Control Bus:-Control instruction carrying part of the system.
 Address Bus:- Memory address carrying part of the system.
 I/O Bus:- It’s a separate type of bus that connects Input , output and other
external devices to the system.

Types of Software
A software or computer software essentially a type of programs which enable the users to
perform some particular tasks or usually used to operate the computer. A software plays a
key role between the user and the machine. In its absence none of the machine can
perform any task.

Generally there are two main types of softwares-

Software
System
Operating System

Language Processor

Application
Presentation

Database

Word processing

System Software:- It is a software which is used to manage the behavior of the computer
hardware to perform basic functionalities which are needed by the user. It acts as an
intermediator between the user and the hardware.
The system software can be further classified into two categories:-
1) Operating System:-
It’s a program which act as an interface between user and machine. An OS is an
important component of a computer which controls all other components of the
computer system.
There are various types of OS are available like single user OS, Multi User OS, Time
Sharing OS, Real Time OS, Multiprocessing OS, Distributed OS etc.
2) Language Processors:-
The software that translates the source code(Program-code written by the
programmer using any programming language) into an object code or machine code (
Code usually in machine language or binary code, that a computer can understand easily
and runon hardware).

There are three types of language processors are there:-


i) Assembler:- converts program written in Assembly language to machine language.

ii) Inerpreter:- System software that translates and execute instructions written in
program line-by-line.

iii) Compiler:- System Software that translates and executes the whole instructions
written in computer program in a single go.

Application Software:- These software are designed to perform some specific tasks only
like writing, listening, music etc. For all these requirements user needs a software for each
type and that specific software is designed for that specific purpose only which are called
Application software.

Difference between System software and Application software:-

S No. System Software Application Software


1 There is no user interface is Interface is present for each specific
present software
2 User cannot see the system User can see the application using GUI
software and cannot work on in it and can also work on that application
3 It starts running whenever system It will only get run when user wants it to
gets on and runs till the system run.
gets off
4 User cannot uninstall system User can install as well as uninstall the
software software
5 It is general purpose software It is specific purpose software

Chapter 2
 Two examples of each type of conversions.
 Octal and hexadecimal value table
Chapter 3
Boolean Logic
Logical Operations:-
1) Logical Operators:- Truth table is a table which represents all the possible values of logical
variables/statements along with all the possible results of the given combination of values.
Basically there are three logical operators are there:-

i) AND ii) OR iii) NOT


AND operator:- This operator performs operation of Boolean Multiplication and the symbol used
is (.) dot. Thus X.Y read ans X AND Y. The result of AND operator will only be TRUE if all the input
values are True else the result will be False.
X Y X.Y
0.0=0
0.1=0 0 0 0
1.0=0 0 1 0
1.1=1 1 0 0
1 1 1
Where 0 represents False and 1 represents True .

OR Operator:- This operator represents Boolean Addition and the symbol used is (+) plus. Thus
X+Y read as X OR Y. For OR the possible input and output conditions are:-
X Y X.Y
0+0=0
0 0 0
0+1=1
0 1 0
1+0=1
1 0 0
1+1=1
1 1 1
In OR operator result will get True if any of the given condition becomes True, the result will only
be False if all the conditions are False.

NOT operator:- This operator operates on single value and operation performed by NOT is called
Complementation and the symbol used is bar. Thus X means Complement of X

0=1 X X
1=0 0 1
1 0

Basic Logic Gates


1) And Gate:-
For a 2-input AND gate, the output Q is true, if BOTH input A and input B are both true,
giving the Boolean Expression of (Q=A and B).
2) OR gate (inclusive OR):-
For a 2-input OR gate, the output Q is true if EITHER input A OR input B is true, giving the
Boolean Expression of (Q= A or B)

3) NOT gate(Inverter)
For a single input NOT gate, the output Q is PNLY true when the input is NOT true, the
output is the inverse or complement of the input giving the Boolean Expression:
(Q = NOT A).
4) input NAND (Not AND) Gate
For a 2-input NAND gate, the output Q is NOT true if BOTH input A and input B are true,
giving the Boolean Expression of (Q = not(A AND B)).

5) input NOR (Not OR) gate


For a 2-input NOR gate, the output is Q is true if BOTH input A and input B are not true,
giving the Boolean Expression of ( Q= not (A OR B))

De-Morgans Theorem
De-Morgan has suggested two theorems which are extremely useful in Boolean Algebra.

Theorem 1
A.B= A+ B
NAND= Bubbled OR

he table shows verification of the De-Morgan’s first theorem


Also write two examples of truth table and three circuit diagrams
given in your book

Chapter 5
Problem solving
Definition of flowchart with all its symbols, algorithm, problem solving cycle
with its sequence.
Two examples of flowchart and algorithm have to write given in your book

Chapter 6
Getting Started with Python
Python is a high level, interpreted, interactive and Object Oriented programming language, which
is developed by Guido van Rossum during the year 1985-1990. It has fewer syntactical
constructions than other languages.

Python is Interpreted bcoz it get processed at runtime by the interpreter, means programmer
don’t need to compile the program before execution.

Python is Interactive bcoz user can directly interact with the python prompt to write their
programs.

Python is Object Oriented bcoz it supports that kind of programming technique in which
encapsulate code within objects.
Modes in Python
Python supports two different modes for writing our program:-

1) Interactive Mode 2) Script Mode

Interactive mode:-
This mode is also known as REPL which provides us a quick way to write our program in
a single line. The code will get executed via Python Shell which comes with Python installation.
To work with this mode, we need to open Python IDE. The >>> indicates that the Python shell
is ready to execute and send command to the Interpreter.

Script Mode:-
In this mode programmer have to write code in a text file and then save it with the .py
extension. After writing the complete code, for its execution we need to click on “RUN” then
“RUN MODULE” or simply press F5. We can execute our program from the terminal of the OS.
For this we have to use a keyword python followed by the name of the file with .py extension.

Difference between Interactive and Script mode

1) In script mode, a file must be created and saved before its execution.
In Interactive mode the result is returned immediately whenever we press Enter key.

2) In Script mode, user can directly edit the command or code given which is not
possible in Interactive mode.

Chapter 7

Python character Set


Character set is a set of valid characters that a language can recognize. A character represents a
letter, digit or any other symbols. Python has the following character set:

 Letters (a-z, A-Z)


 Digits (0-9)
 Special Symbols (space bar, +, *, &, ^, %, $, # etc)
 Whitespaces (Blank space, tabs, carriage return, newline )
 Other characters ( all ASCII and UNICode characters )
Tokens
The smallest individual unit in a program is known as Token or a lexical unit. Python has the
following Tokens:-
i) Keywords ii) Identifiers iii) Literals iv) Operators v) Punctuators
Keywords:- A keywords is a word having special meaning reserved by programming language.
These are reserved for special purpose and must not be used as normal identifier names. Some ex
are False, for, if, append, as, return and many more.

Identifiers:- Identifiers are the fundamental building blocks of a program and are used as the
general terminology for the names given to different parts of the program by a variables, objects,
classes, functions etc.
In python an identifiers starts with a letter A-Z or a-z an underscore( _ ) followed by zero or
more letters, digits (0 to 9)
Python does not allow any kind of special characters like & % $ with an identifiers.
Python is a case sensitive programming language.

Some valid identifiers are:- MyFile, Date9_77, _abc, MYFILE, File13

Some invalid identifiers are:- Data-rec, 29CLCT, 2x, My.file, $34

Literals/value:- Literals (referred as Constant values) are data items that have a fixed value.
Python allows several kinds of literals:-

i) String Literals:- is a sequence of characters surrounded by quotes(Single or double or triple)

ii) Numeric Literals:- This literal is capable to hold any type of numeric values like integers,
decimals, complex values.

iii) Boolean Literals:- This literal is used to represent one of the two Boolean values i.e True or
False. This literal can either have value as True or False.

String Types in Python:-


Python allows two types of strings:-
i) Single Line String:- String that enclosed in single quote(‘ ‘) or double quote (“ “) i.e they must
terminate in one line.
Ex:- x=”Hello”
y=’hello I am
python’

ii) Multiline String:- String across multiple lines called Multiline String. Multiline strings can be
created in two ways:-

a) By adding a backslash at the end of a normal single quote /double quote string
Ex:- x=”hello\
world\
i am\
python”
b) By typing the text in triple quotation marks
Ex:- x=’’’hello
World’’’

Operators:- Operators are the tokens that triggers some computations when applied to variables
and other objects (i.e operands) in an expression. Python supports:-

ii) Binary Operator:- These operators require two operands. All the Arithmetic, Bitwise, Shift,
Identity, Relational, Logical, Assignment and Membership Operators are Binary operators.
Arithmatic Operators:-
+ Addition
− Subtraction
* Product
% Remainder/
Modulus
** Exponent
/ Division
// Floor Division
IdentityOperators:-
is is the identity
same
is Is the identity not
not same
Relational Operators:-
< Less than
> Greater than
<= Less than equal
to
>= Greater than
equal to
== Equal to
!= Not Equal to
Logical Operators:-
AND Logical AND
OR Logical OR

Assignment Operators:-
= Assignment
/= Assign Quotient
+= Assign sum
*= Assign product
%= Assign remainder
−= Assign difference
**= Assign Exponent
//= Assign Floor
division
Membership Operators:-
in Whether variable in
sequence
not Whether variable not in
in sequence
Chapter 8
Data Handling
Data Types
Python Data Types

Numeric Dictionary Boolean Set Sequence Type

Integer Strings

Complex
List
Number

Float Tuple

Numbers:-stores numeric values like integer, float and complex values. Python supports three
types of numeric data:-

1) Int:- for integer values like ( -20,30, -300 etc). Python has no restrictions regarding the
Length.

2) Float:- used for decimal values like 102.5, 2.7 etc. It is accurate upto 15 decimal places

3) Complex:- contains an ordered pair like x+iy, where x and y represent real and imaginary parts
respectively. Ex. 2.3j, 2+3j, 2.5 + 4,5j

Dictionary:- It is an unordered set of a key-value pair of items where each key stores a specific
value. The items in the dictionary are separated with the comman(,) and always enclosed in a
curly braces ({} )

Ex d = {1:’a’,2:’b’,3:’c’, 4:’d’ }
Boolean:- It provides two built-in values i.e True and False. This data type is denoted by the
keyword bool .True values are represented by 1 or ‘T’ and False value by 0 or ‘F’

Set:- It is unordered collection of the data type which can be modify also after the creation and
has unique elements. In Set, order of the element is undefined, may return the changed sequence
of the elements. It is created by the keyword set()

Ex:- set={‘a’,1,2,’b’}

Sequence Type:-
1) String :- Set of characters called String. We can create String by simply enclosing the
characters in single quote (‘ ‘) or, double quote (“ “) or triple quote (‘ “ “ ‘) Python treats single
and double quote equally. String creation is as simple assigning values to a variable.
x=”Hello world”
x=’hello world’
Some special charactes supported by the string data type are:-
1) + (Concateation)The process of adding two or more string together.
Ex: “hello” + “ Python” we get hello python

2) * (Repetition) Used for creating multiple copies of a particular string.


Ex: “ Python” *2 returns Python Python
“Python” *3 returns Python Python Python

3) [] (Slicing) Gives the character from the given index value


Ex: x=”hello”
Print(x[1])
e

4) [ : ] (Range of Slice) gives the characters from the given range


Ex: x=”hello World”
Print(x[1:7])

ello Wo

Python Standard Library Modules


A python module is a file which contains some variables and constants, some functions, objects
etc defined in it which can be used in other python program. To execute any module in our program first
we need to import the module in our program using ”import” keyword.
Python standard library has many modules for different functionalities like math module, random
module, statistics module and many more.

1) Math module:- To use this module firstly we need to import this module in our code using
import.math
Then after importing the module we are able to access the functions available in the math module using
math.<function_name>

2) Random Module:- This module generate random numbers, i.e. a number generated by chance. To
use this module user must have to import a module via
Import random

Three most common random number generator functions in random module are:-
i) random() :- returns the floating point number in the range of 0.0 to 1.0.

ii) randint(a,b):- returns floating point number from in between the given two integer values
i.e a and b

iii) randrange(<start>,<stop>,<step>):-
returns number in between start..stop with step value .

Using randrange() function:-


This function can be used in three ways
i) random.randrange(<Stopvalue>):- return random number from in between 0 to given <stopvalue>.
>>>random.randrange(45)
13

ii) random.randrange(<startvalue>, <stopvalue>):- generate random number from in between the given
<startvalue> and <stopvalue>
>>>random.randrange(10,20)
18

iii) random.randrange(<start>,<stop>,<<step>):- generate random number from in between the given


start and stop value with the difference of given step value.

>>>random.randrange(10,40,6)
22

3) Statistics module:- This module of Python provides many statistical functions like mean(), median(),
mode() etc. To use these function user needs to import a file called
Import statistics

We can use these function after importing the module by using

i) statistics.mean(<seq>) :- returns the average value of the given sequence

ii) statistics.median(<seq>):- return the middle value from the given set values.

iii) statistics.mode(<seq>):- return the most often repeated value from the given sequence.

Ex:-
>>>import statistics
>>> seq=[3,4,2,8,5,4,5,9,5,2]
>>>statistics.mean(seq)
12.5
>>>statistics.median(seq)
5
>>>statistics.mode(seq)
5

Concept of Lvalues and R Values, Error and its types also have to write

Chapter 9
Flow of Control

Statement:- Statements are the instructions given to the computer to perform any kind of action. It
forms the smallest executable unit within the python program.
Python supports three types of statements:-

1) Empty statement:- The statement which does nothing is called empty statement. In python the
empty statement is pass statement. This pass statement moves to the next statement in the flow of
control. This pass statement is useful for that instances when syntax of the language requires the
presence of the statement but where the logic of the program does not.

2) Simple statement:- Any single line executable statement is a simple statement in python. For ex:-
print(x), x=5 etc

3) Compound statement:- It represents a group of statements executed as a unit. The compound


statement of python is written in a specific pattern shown below:-
<compound statement header>:
<body containing multiple simple or compound statements>
Ex: if x>y:
sum=x+y Compound statements
print(sum)
else:
print(“Sorry”) Simple statement
Conditional Statement in Python
Statements which perform different computations or actions depending upon whether a specific
Boolean expressions evaluates either True or False, called Conditional Statements. These
statements are handled by ‘if’ keyword
1) if… Statement:-
This statement will only run when the given condition inside the body of the statement
becomes true and carries out some instructions and does nothing in case condition
evaluate to false.
Syntax:- if [boolen expression]:
Statement

Example:- if 2<100:
Print(“yes”)

2) if-else… Statement:-
Along with the if statement the else condition can be optionally used to define an
alternate block of statements to be executed, if the given Boolean expression return false i.e if
expression returns true value it carries out all the instruction indented inside the ‘if’ and if the
condition become false it carries out the instruction indented in side the ‘else’.
Syntax:- if [boolean expression]:
Statement 1
Else :
Statement 2

Example:- if 2>3:
Print (“2 is greater”)
Else :
Print(“3 is greater”)

3) elif statement:- This condition is used to include multiple conditional expressions between
if and else statement because sometime we need to check another condition the one condition
returns false and so-on.

Syntax:- if(Boolean expression):


Statement 1
Elif(Boolean expression):
Statement 2
Elif(Boolean expression):
Statement 3
Else:
Statement 4
Example:- x=40
If x==10:
Print(“value of x is 10”)
Elif x=40 :
Print(“value of x is 40”)
Else :
Print(“value of x is something else”)

4) Nested if statement:- Condition inside the condition is nested condition. Sometimes it is


needed to check some other condition if the above condition returns True or false. This nested
condition exists either inside the ‘if’ statement or inside the ‘elif’ statement or inside the ‘else’
statement.
Syntax:- if < condtional expression >:
If<condtional expression>:
Statement(s)
else:
statement(s)
elif< condtional expression>
If<condtional expression>:
Statement(s)
else:
statement(s)
else:
statement(s)
Iterative Computation and Control Flow
In Python, the iterative statements are also known as looping statements, which are used to
execute a part of program repeatedly as long as the given condition is True.
Loop comes with three parameters i.e initialization, condition and increment/decrement
operator.
Python provides two types of iterative statements:-

1) While statement 2) For statement

While Statement:-
A while loop is a conditional loop that will repeat the instructions within itself as
long as the condition remains True. This loop is also known as Control loop statement
because in this loop condition gets verified initially, then the execution of the statements is
determined based on the condition result.
Syntax:- while[Boolean expression]:
Statement1
Statement 2
.
.
Statement n

A while loop in python is processed as:-


 Initially it checks the conditional expression give, either it is True or False.
 i) if it is True, then all the statements given inside the body of the loop get executed.
ii) if it is False, then then control moves to next statement present outside the loop.
 It continues the same, till the given condition becomes False.

Example:- num=0 // initial value 0


While num <=5: // condition is <=5
print(“num = “, num) //loop-body
num=num+1 // update expression

Output:- num =1
num =2
num =3
num =4
num =5

For Statement:-
In python, the For loop is used with sequence types like list, tuple and set.The for
statement is used to repeat the execution of a set of statements for every elements of a
sequence. In this loop there is no such condition to check the loop initially before the
execution begins.

A for loop in python is processed as:


 The loop variable is assigned the first value in the sequence.
 All the statements in the body of the loop get executed with an assigned value.
 Then loop assigned new value and loop get executed again with the new value.
 Process continues till the last value in the sequence get processed.
Syntax:- for <variable name> in <sequence>:
Statement1
Statement2
.
.
Statement N
Example:- x=[10,20,30,40]
for i in x:
print(i)

Output:- 10
20
30
40

Example:- for x in range(1,6):


print(x)
print(“Job is DONE”)

Output:- 1
2
3
4
5
Job is DONE

Jump Statement-break and continue

Jump statements in python are used to alter the flow of a loop like you want to skip a
part of a loop or terminate a loop. Python offers two jump statements to be used
within loops , break and continue statements

Break Statement:-
Break statement is used to exit from the iterative statements (loops) such as for,
while loop. Use of this statement terminates the execution of loop immediately, and then
program execution will jump to the next statements.
Syntax:- while condition1:
Statement 1
Statement 2
If condition2:
Break

For var in sequence:


Statement 1
Statement 2
If condition2:
Break

Continue Statement:-
This statement is used to continue the loop execution i.e to get back to the top of
the iterative statements (loops) like for, while. US of this statement stops the further
statement execution of loop immediately.

Syntax:- while condition1:


Statement 1
Statement 2
If condition2:
continue

For var in sequence:


Statement 1
Statement 2
If condition2:
continue

Chapter 10
String Manipulation

Strings:- Any sequence of characters is called String. Strings are enclosed in single (‘ ‘) or
double (“ “) or Triple (“ ‘ ‘ “) quote. Each and every character has a unique index values.
The indexes of any string begin with the index value 0 to length-1

String Operators:- String operators are basically + (concatenation), * (Replication) and


membership operators i.e in and not in along with all relational operators.

Basic String Operators:- The two basic String operators are + and * which is used for
Concatenation and Replication rather than addition and multiplication.

i) String Concatenation Operator (+):- This operator is used to create new String by joining
two or more operand strings. Ex:- “Tea”+”Pot” gives TeaPot
ii) String Replication Operator (*):- This operator is used to create multiple copies of a
given string. This operator is used with one string with one integer operand. For ex:-
3*”go!” give go!go!go!, “go!”*4 gives go!go!go!go!
For replication string both operand values cannot be of String type.

Membership Operator:- There are two membership operators for strings, these are in an
not in operators.
 in – this operator return True if a character or a substring exists in the given string,
else return False
 not in – this operator return True if a character or a substring does not exists in the
given string else return
False.

Ex:-
“a” in India True
“dia” in “India” True

Ordinal Function ( ord() ):-This function takes single value as an input and as a result
return its UNICODE value.

Syntax:- ord(<single character>)


Ex:- >>> ord(‘A’)
65

Character Function(chr()):- This function works just opposite to ord() function, in which it
takes value as an input and return character corresponding to that value.
Syntax:- chr(<int>)
Ex:- >>>chr(65)
A

String Functions
1) capitalize():- This function convert first character of a sting to uppercase and lowercase all
other characters, if any.

Syntax:- String.capitalize()

Example:- “ hello this is python”.capitalize()

Output:- Hello this is python

2) count():- This function returns the number of occurrences of a substring in the given string
String i.e this method searches the substring in the given string and returns how many times the
substring is present in it.
It also takes optional parameters “start” and ‘end” to specify the starting and ending position
in the string respectively.

Syntax: string.count(substring)

Ex. “ Python is a awesome, isn’t it”.count(‘is’)

Output:- The count is : 2

Ex:- 2) ” Python is a awesome, isn’t it”.count(substring, 8,25)

Output:- The count is : 1

3) find():- It returns the index of the first occurrence of the substring (if found). If not found return
-1.

Syntax:- str.find(sub, start, end)

Ex:- ” Computer”.find(‘w’)

Output:- -1
” Computer”.find(‘o’)
Output:- 1

4) index():- It returns the index of a substring inside the string(if found). If the substring is not
found, it raise an exception. It is similar to find but the only difference is that find return -1 in case
of substring not exists where as index throw an exception.

Syntax:- str.index(sub, start, end)


Example:- ” Computer”.find(‘w’)

Output:- Error
” Computer”.find(‘o’)
Output:- 1

5) isalnum():- This method returns true if all the characters in the string are alphanumeric( either
alphabets or numbers). If not, it return false

Syntax:- string.isalnum()

Ex:- >>> ”m442342onika”.isalnum


>>> yes
>>>”M4234.onika34er.isalnum()
>>>False
>>>”moni432ka534Goy42al
>>>True

6) isalpha():- returns True if all characters in the string are only alphabets else return False.

Syntax:- string.isalpha()

Ex:- >>>”m442342onika”.isalpha()
>>>False
>>>”Bill Gates”.isalph()
>>>False
>>>”AmitabhBacchan”.isalpha()
>>>True

6) isdigit():- returns True if all characters in the string are only digits else return False.

Syntax:- string.isdigit()

7) islower():- returns True if all characters in the string are lower case alphabets if it contains at
least one uppercase alphabet it return False.
This function doesn’t take any parameters.

Syntax:- string.islower()

8) isupper():- returns True if all characters in the string are upper case alphabets if it contains at least one
Lowercase alphabet it return False.
This function doesn’t take any parameters.

Syntax:- string.isupper()

9) lstrip():- It returns a copy of the string with leading characters removed (based on the argument
passed). This lstrip() function removes the characters from the left based on the argument (a string
specifying the set of characters to be removed)

Syntax:- string lstrip([chars])

10) strip():- This method returns a copy of the string by removing both the leading and the trailing
characters (based on the string argument passed). When the characters of the string in the left
mismatches with all the characters in the chars argument, it stops removing the leading characters
and vice versa.

Syntax:- string.strip([chars])

11) Replace():- This method returns a copy of the string where all occurances of a substring is
replaced with another substring. The syntax of replace() is:-

str.replace(old, new)

You might also like