This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Checking the standard deviation of above list | |
## Here printing upto 3 decimal places. | |
print('%.3f' %st.stdev(l)) | |
#[Output]: | |
#32.496 | |
## Checking the variance. | |
print('%.3f' %st.variance(l)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l1 = [1,2,3,4] | |
print(l1) | |
#[Output]: | |
[1, 2, 3, 4] | |
print(l1[0]) | |
print(l1[1]) | |
#[Output]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Lists are heterogenous in nature. | |
l3 = ['a' ,1, 'hello'] | |
print(l3) | |
#[Output]: | |
#['a', 1, 'hello'] | |
## Lists are mutable in nature. | |
l2 = l1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## len() method | |
## Checking previously defined l3. | |
print(len(l3)) | |
#[Output]: | |
3 | |
## in operator | |
if 'a' in l3: | |
print('Yes, this element is in the list') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Checking the index of '1' | |
l3.index(1) | |
#[Output]: | |
#1 | |
## Here we start searching beyond the index in which '1' lies so it throws ValueError | |
l3.index(1,2) | |
#[Output]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Append() method | |
## It added one more new element '7' in the last. | |
l4.append(7) | |
print(l4) | |
#[Output]: | |
[1, 2, 3, 2, 3, 4, 5, 6, 7] | |
## We can also add sublist as an element in the original list as we saw earlier, list is ## heterogenpus in nature. | |
l4.append([1,2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## pop() method | |
l4.pop(5) | |
print(l4) | |
#[Output]: | |
#[1, 2, 3, 2, 3, 4, 5, 6, 7, [1, 2], 'a', 1, 'hello'] | |
l4.pop() | |
print(l4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## sort() method | |
l5 = [4,5,1,2,8,9,1] | |
## It will sort the list in ascending order. | |
l5.sort() | |
print(l5) | |
#[Output]: | |
#[1, 1, 2, 4, 5, 8, 9] | |
l5 = [4,5,1,2,8,9,1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open('student_details.csv' , 'r') as csv_file1: | |
file1 = csv.reader(csv_file1) | |
## It will print the csv reader object. | |
print(file1) | |
## It will print each line as a list | |
for line in file1: | |
print(line) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('student_details.csv' , 'r') as csv_file1: | |
## Reading csv file | |
file1 = csv.reader(csv_file1) | |
## Now we are creating new file to write a content. | |
## If this file doesn't exist already then it will create on its own. | |
## Opening in write mode. | |
with open('student_details2.csv' , 'w') as csv_file2: | |
## Using a 't' delimiter to store values. | |
file2 = csv.writer(csv_file2, delimiter='-') | |
## Reading line from file1 and then writing in a new created csv file. |