Skip to main content

Practice questions on Datatypes and Datastructure

Here are some examples for your practice:

Examples on Datatypes.

1.) 

j = 100

k = 99

j != k

k = j

print(k) 


2.) c = 4*1**4

print(c)


3.)b = int(22.22+2/2)

print(b)


4.)a = "7"

b = int(a)

print(len('apple')*a)


Example on Datastructures


6.) a = 1,2,3,4,5

print(type(a))


7.)Tuple1= ("Black",[1,2,3],[4,5,6])

print(Tuple[1][1])


8.)Tuple2= "White",10,"Green"

a,b,c=Tuple2

print(a)


9.)Tuple3=(1,2,3,4,5,6,7,8,9)

print(Tuple3[2:5],Tuple3[:4],Tuple[3:])


10.)Tuple4=(10,20,30,40,50)

print(Tuple4[-1])

print(Tuple4[-4:-1])


11.)List1 = [4,3,9,7]

List1[1:4] = [2,8,6]

print(List1)


12.)List2=['xyz','zyx','yxz']

print(max(List2))


11.)a,b,*c,d,e=[1,2,3,4,5,6]

print(c)


12.)Set1={"Lion","Tiger","Zebra"}

Set1.update("Rhino")

print(Set1)


13.)Set2={"Lion","Tiger","Zebra"}

y={"Rhino"}

Set2.update(y)

print(Set2)


14.)d = {}

print(type(d))


15.) Exercise on list:

You have a list of colors 

colors = ["Red","Green","Violet","Orange","Yellow"]

Using this find out:

1.Length of the list.

2.Add 'White' after 'Red'.

3.Count number of time 'Violet' occured.

4.Now remove 'Orange' and replace it with 'Brown'

5,Sort the Colors list in alphabetical order.


16.)Exercise on Set

You have a set 

Set1 = {1,2,3,4,"a","b","c","d","e"}

1.add 7 into set.

2.insert "z","x","v" at a time into set.

3.remove "a".

4.perform pop operation on the set.

5.typecast it to some other datastructure.


17.) Exercise on Dictionary

Create a Dictionay with employee id as key and name as value.

1.Print keys

2.Print values

3.Pop employee 3

4.change name of employee with  employee id :3

5.Enter new employee id and employee name into dictionary .

-Rushi Mahapure

Comments

Popular posts from this blog

Datatypes in Python...

 Basic datatypes  in python are String Integer Float Complex Numbers  Built-in datastructures  list tuple set dictionary Built-in methods on String: stringname.capitalize() - First letter of string is converted in uppercase stringname.casefold()  - Converts string into lower case stringname.upper()-Coverts the whole string into uppercase. stringname.lower()-Converts the whole string into lowercase. stringname.count()- Prints the number of times a specific value is occurred stringname.isnumeric() - Returs whether the values in string are numeric or not stringname.isupper() - Returns whether the string is in uppercase or not i.e True or False stringname.islower() - Returns whether the string is in lowercase or note i.e True or False stringname.startswith("suffix") - Tells whether the string starts with particular suffix stringname.endswith("prefix") - Tells whether the string ends with particular prefix for more similar methods run print(dir("stringname")) L...

Why Python...?

 Many programming beginners come up with the thought Why Python.? Here are some reasons.. 1.)Easy to Understand and Learn. 2.)Support From Major Corporate sponsors 3.)Hundreds of Libraries and Many Frameworks. 4,)Versatile,Efficient,Fast. 5,)Hottest trends like Bigdata,Machinelearning,CloudComputing need Python  Guddo von Russom created python in 1980s with clear view to make it a general purpose language The major reason behind popularity of python is in simplicity in its syntax.And it is interpreted which makes it more popular among developers. -Rushi Mahapure