CS Practical Shubhang Shrivats
CS Practical Shubhang Shrivats
Acknowledgement
Firstly, I would like to thank our computer science
teacher, because he always supported and guided us
while doing this project. He very well cleared all
the doubts I had regarding this project. Also, I
would like to especially thank my parents and
friends who helped me a lot to complete this
project.
Output:-
Functions In
String
List In Python
A list is a data type that allows you to store various types data in
it. List is a compound data type which means you can have
different-2 data types under a list, for example we can have
integer, float and string items in a same list.
Create a List
We create a list by placing elements inside [], separated by
For example,
In the above example, we have created a list named languages.
Here, we can see each list item is associated with the index
number. And we have used the index number to access the items.
6
Functions of List
Creating a Tuple
A tuple is created by placing all the items (elements) inside
parentheses (), separated by commas. The parentheses are
optional, however, it is a good practice to use them.
A tuple can have any number of items and they may be of
Create a Dictionary
We create a dictionary by placing key-value pairs inside curly
Output:-
Explanation:
In the above code, we have defined a bubble_sort() function which
takes list1 as an argument.
• Insidethe function, we have defined two for loop - first for loop
iterates the complete list and the second for loop iterates the list
and the compare the two elements in every outer loop iterations.
• The for loop will be terminated when it reaches at the end.
• We have defined the condition in the inner for loop; if a first
index value is greater than the second index value, swap their
positions with each other.
• We called the function and passed a list; it iterated and returned
the sorted list.
-Built-in Functions
Built-in functions are already defined in python. A user has to
remember the name and parameters of a particular function. Since
these functions are
pre-defined, there is no need to define them again.
Some of the widely used built-in functions are
Functions Description
Modes Behaviour
r, r+, w+, a+, x+ Read
r+, w, w+, a, a+, Write
x+
w, w+, a, a+, x, Create
x+
r, r+, w, w+, x, x+ Pointer Position Start
a, a+ Pointer Position End
w, w+ Truncate (clear contents)
r, r+ Must Exist
x, x+ Must Not Exist