Comments

Python with Stirng

 x = 'MICHAEL'

x[0] = 'M'

x[-1] = 'L'

x[0:3] = 'MIC'

x[::2] = 'MCAL' # it take every second variable.

x[0:5:2] = 'MCA' # retern every second vaiable till 5 where 5 not enter. 

len(x) =  7 

x + 'hello' = 'MICHAEL hello'

3*'hello' = 'hello hello hello'

\n # represented new line 

\ #represented as backslash

\\ # put backslash in the string

y = x.upper() 

z = x.replace('ee', 'dd')

x.find('M')

tuple x=(1,"H", 3, ("D","E")) not mutable

Convert String to List: 

x.split()

list  x = [1,2,3,4] is mutable

x[0] = "D"

del(x[1])

LIST VS Dictionary

LIST contained index, element

Dic contained key, value

Dictionary = {"key1":1, "key2":2}

dic.keys()  // return the keys of dec

dic.values() // return the value of the dec

del(dic[key1]) delete the key with it's value

dic[hello]

set = {"a", "b", "c"}

set.add("n")

set.remove("b")

set1  & set2 = the same element in both of set

set1.union(set2) = all the element in both of sets

set1.issubset(set2)

we can add new list by using x.extend([3,4]) 

x = (("H","D"),("E","N"))
print(x[0][1])
Output// D
Share on Google Plus

About Inas AL-Kamachy

    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment