JOBS ESTATE FREE EMAIL ALERTS

Sequences:-Storing values in an order and retreiveing values by using index value .

X = [“hi”,”hello”,”how are you”]

X[0]  X[1]        X[2]—-index

3 Types of sequences:-

1)Strings

2)Lists

3)Tuples

 

1)Strings:- Collection or Group of characters.

  • Denotes in Double quotes(“) or Single quote(‘).
  • Python treats Single or Double quotes are same because of there is no character data type.
  • python is case-sensitive language.

 

#Declare a string

s = “bobby”

s1 = ‘tom’

s+s1

‘bobbytom’

s+” “+s1

‘bobby’ ‘tom’

 

0xc122

bobby

#how to update a  string

   s

s = “bobby”

0xc32

tom

s1 = ‘tom’

 s1

1×23

jerry

s1 = ‘jerry’

s+s1

immutable

‘bobbyjerry’

 

 

 

#clear contents of a string

S = “”; —>give empty value so that clear the value.

 

#Remove the string completely from memory Manually

del s;

#how to access the content value of  a string

s = “My channel name is bobby”

s[0]—–>1st character—->’M’

s[0:5]—>returns the sub string between 0 index to 4–>’My  ch'(calculates space index also)

s[5:]——>returns all characters starting from index 5–>’annel name is bobby’

s[:10]—->returns all the characters  from index 0 to 9–>’My channel’

 

Strings indexing:- positive or negative indexing

 

   -4-3-2-1

s=”ABCD”

      0123

 

s[0]—>’A’

s[-2]—>’C’

 

String Functions:-

s = “Hello How are you “

Length—>len(s)—->17

Maximum as per ascii value—>max(s)—–>’y’

Minimum——->min(s)——>’ ‘

 

Built in functions:-

s=”abcd”

  1. capitalize()–>Capitalize first character of a string–>s.capitalize()–>Abcd
  2. center(width)–>s.center(50)–> abcd
  3. endswith(substr,beg=0,end=len(string))–>endswith(‘c’,0,4)–>False
  4. find(substr,beg,end)—>find(‘b’,0,5)—>1
  5. isalnum()——–>isalnum()———>True
  6. isalpha()———->isalpha()———->True
  7. isdecimal()———>isdecimal()——–>False
  8. isdigit()————–>isdigit()————>False
  9. islower()————>islower()———->True

 

 

  1. Lists:-It stores set of Objects.

Declare with in square brackets.[  ]

Create a List:-

S = [1,2,3,4.5,”bobby”]

 

S = [1,2,[3.5,4.2]]——>inner lists

 

Retrieve elements:- same as strings—s[0]—>1

update elements:-

s[1]=10——–>[1,10,3,4.5,’bobby’]

while updating it cannot create separate memory location like strings.

 

remove an element from  list:-

del s[2]——->[1,10,4.5,’bobby’]

 

delete complete list:-

del s——>NameError:name ‘s’ is not defined.

 

Operators in List:-

s =[10,20]

s1=[10,30]

s2=[10,20]

 

i)Standard operators: == <>

s==s1———>False

s>s1———–>False

s<s1———->True

 

ii)Sequence Operators:

s[0]

s[0:3]

 

iii)Membership operators: in ,not in—–>checks available or not in the list

s=[10,20]

s—>[10,20]—->10 in s—->True

                   ——>12 in s—->False

                  ———>12 not in s—>True

 

iv)Concatenation:- using + operator

s=[10,50]

s1=[10,60,90]

s+s1—->[10,50,10,60,90]

 

v)Repitition Operator:- using * operator

s*2——>[10,50,10,50]

 

Bulit in Methods in List:-

  1. append(obj)
  2. count(obj)
  3. index(obj)
  4. insert(index,obj)
  5. reverse()

 

Example:-program in cmd

>>> s=[10,20]

>>> s

[10, 20]

>>> s.append(30)

>>> s

[10, 20, 30]

>>> s.count(20)

1

>>> s.count(40)

0

>>> s.index(20)

1

>>> s.index(30)

2

>>> s.insert(1,90)

>>> s

[10, 90, 20, 30]

>>> s.reverse()

>>> s

[30, 20, 90, 10]

>>> 

 

3)Tuples:- same as List—>( )—>Read only List

Declare with in parenthesis.()

we cannot update values in Tuples because it is read only .

All operations are same as List

 

s = (10,20,30)

Example:-

C:\Users\bobby>python

Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AM

D64)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

>>> s=(10,20,30)

>>> s

(10, 20, 30)

>>> s[1]=50

Traceback (most recent call last):

  File “<stdin>”, line 1, in <module>

TypeError: ‘tuple’ object does not support item assignment

>>> 

© Copyright 2020 Jobs Estate All Rights Reserved