Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Python subject

Uploaded by

David Sathurag
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python subject

Uploaded by

David Sathurag
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

String opertors:

1. Concatenation (+):

It is used to concatenate two strings.

Eg: str1= “ Hai”

Str2= “Welcome”

Str3= str1+str2

Print(str3)

O/P : Hai Welcome

Repetition (*):

(*) operator is used for repetition (Repeat n no. of times)


Eg: str1= “Hello world”
Str3=str1*3
Print(str3)

O/p: Hello world, Hello world, Hello world

Boolean methods:

Sting methods that will evaluate to a Boolean value. The methods are useful
when we creating forms for the user to fill. Eg., for Postal code it will accept only
numeric string.

Methods:

Str.isalnum( )-> Check whether the string contain alpha numeric characters
Str.isalpha( ) -> String consists only alphabetic character

Str.islower( ) -> Check whether the string characters are in lower case

Str.isupper( ) -> Check the string characters are in upper case

Str.isspace( ) -> Checks all the characters are white space character

Str.istitle( ) -> String is in title case (Python title case)

String Modules:

The modules contains number of methods to process std python string.

Eg: import string

text= “programming subject”

print(“upper( )=”, text.upper()

print(“lower()=”, text.lower()

print(“split( )=”, text.split(i)

print(“replace( )=”, text replace (“subject”, “book”)

print(“find( )=”, text.find(p)

print(“count( )=”, text.count(m)

O/P: upper( )= PROGRAMMING SUBJECT

lower( )= programming subject

split( )= [‘program’ , ‘ng’ subject]


replace( )= Programming book

find( )=0

count( )=2

List as array

Instead of array we can use list and list functions & methods.

List in python is a collection of items which can be any type. Array is


collection of items of single type. When comparing list and array. List is more
flexibility.

List is also a dynamic mutable type and this means you can add and delete
elements from the list at any time.

To define the list:

mylist=[1,2,3,4,5,6,7]

Accessing using index & string:

print(mylist[2]) ->3 (o/p)

mylist[2]=100

print(mylist)-> [1,2,100,4,5,6,7]

print(mylist[2:5]) ->[100,4,5]

print([0:]) ->[1,2,100,4,5,6,7]

print([:]) ->[1,2,100,4,5,6,7]
print([:5]) ->[1,2,100,4,5]

Basic list operators:

 Concatenation: (+ operator)

Used to join two or more list

Eg: a=[1,2]

b=[4,5]

c=a+b

print(c ) -> o/p [1,2,4,5]

 Repetition:

Used to repeat the list n times

Eg: a=[1,2]

c=a*2

print(c ) ->[1,2,1,2]

You might also like