ANNAMACHARYA INSTITUTE OF TECHNOLOGY
AND SCIENCES(AUTONOMOUS),KADAPA.
PYTHON
LAB MANUAL
(R23 –REGULATION)
1)
Aim: To write the program to find the largest element among three numbers.
Desccription:
Initialize three numbers by n1, n2, and n3. Add three numbers into the list lst =
[n1, n2, n3]. . Using the max() function to find the greatest number max(lst).
And finally, we will print the maximum number.
Program:
# Python program to find the largest number among the three input numbers
# change the values of num1, num2 and num3
# for a different result
num1 = 10
num2 = 14
num3 = 12
# uncomment following lines to take three numbers from user
#num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
Output:
The largest number is 14.0
Result:The python program to find the largest element among three numbers
was successfully completed.
2)
Aim:The program to display all prime numbers within an interval.
Description:
A prime number is a natural number greater than 1 that has no positive
divisors other than 1 and itself. The first few prime numbers are {2,
3, 5, 7, 11, ….}.
The idea to solve this problem is to iterate the val from start to end using a
Python loop and for every number, if it is greater than 1, check if it divides n.
If we find any other number which divides, print that value.
# Python program to display all the prime numbers within an interval
lower = 900
upper = 1000
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
# all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
Output:
Prime numbers between 900 and 1000 are:
907
911
919
929
937
941
947
953
967
971
977
983
Result: The python program to display all prime numbers within an interval
was successfully completed.
3)
Aim:To write python program to swap two numbers without using a temorary
variable.
Description:
This program is used to swap values of two variables using the third variable,
which is the temporary variable. So first of all, you have to include the stdio
header file using the "include" preceding by which tells that the header file
needs to be process before compilation, hence named preprocessor directive.
x = 10
y=5
# Code to swap 'x' and 'y'
# x now becomes 15
x=x+y
# y becomes 10
y=x-y
# x becomes 5
x=x-y
print("After Swapping: x =", x, " y =", y)
Output:
After Swapping: x =5, y=10
Result: The python program to swap two numbers without using a temorary
variable was successfully completed.
4)Aim:To Demonstrate the following operators in python with suitable
examples:
a)Arithmetic b)Relational c)Assignment d)Logical e)Bit wise f)Ternary
g)Membership h)Identity.
Description:
#Python Arithmetic operators are used to perform basic mathematical
operations like addition, subtraction, multiplication, and division.
#In Python Comparison of Relational operators compares the values. It either
returns True or False according to the condition.
#Python Logical operators perform Logical AND, Logical OR, and Logical
NOT operations. It is used to combine conditional statements.
#Python Bitwise operators act on bits and perform bit-by-bit operations. These
are used to operate on binary numbers.
#Python Assignment operators are used to assign values to the variables.
#In Python, is and is not are the identity operators both are used to check if two
values are located on the same part of the memory. Two variables that are
equal do not imply that they are identical.
#In Python, in and not in are the membership operators that are used to test
whether a value or variable is in a sequence.
#in Python, Ternary operators also known as conditional expressions are
operators that evaluate something based on a condition being true or false.
4.a)
a=7
b=2
# addition
print ('Sum: ', a + b)
# subtraction
print ('Subtraction: ', a - b)
# multiplication
print ('Multiplication: ', a * b)
# division
print ('Division: ', a / b)
# floor division
print ('Floor Division: ', a // b)
# modulo
print ('Modulo: ', a % b)
# a to the power b
print ('Power: ', a ** b)
Output:
Sum: 9
Subtraction: 5
Multiplication: 14
Division: 3.5
Floor Division: 3
Modulo: 1
Power: 49
4.b)
Initializing the value of a and b
a = 20
b = 10
d = 30
# Calculating the sum of a and b
c=a+b
e=d-b
print("The sum of a and b is ", c)
print("The difference of d and b is ", e)
# Using relational operators
print(a >= b)
print(a != b)
print(c <= d)
print(e == a)
Output:
The sum of a and b is 30
The difference of d and b is 20
True
True
True
True
4.c)
# assign 10 to a
a = 10
# assign 5 to b
b=5
# assign the sum of a and b to a
a += b #a=a+b
print(a)
Output:
15
4.d)
# logical AND
print(True and True)
print(True and False)
# logical OR
print(True or False)
# logical NOT
print(not True)
Output:
True
False
True
False
4.e)
x = int(input("Enter the value of x: ")) # Taking user input for x
y = int(input("Enter the value of y: ")) # Taking user input for y
print("x & y =", x & y)
print("x | y =", x | y)
print("~y =", ~ y)
print("x ^ y =", x ^ y)
print("x >> 1 =", x >> 3)
print("y >> 1 =", y >> 3)
print("x << 1 =", x << 1)
print("y << 1 =", y << 1)
Output:
Enter the value of x: 4
Enter the value of y: 5
x&y=4
x|y=5
~y = -6
x^y=1
x >> 1 = 0
y >> 1 = 0
x << 1 = 8
y << 1 = 10
4.f)
message = 'Hello world'
dict1 = {1:'a', 2:'b'}
# check if 'H' is present in message string
print('H' in message) # prints True
# check if 'hello' is present in message string
print('hello' not in message) # prints True
# check if '1' key is present in dict1
print(1 in dict1) # prints True
# check if 'a' key is present in dict1
print('a' in dict1) # prints False
Output:
True
True
True
False
4.g)
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1,2,3]
y3 = [1,2,3]
print(x1 is not y1)
print(x2 is y2)
print(x3 is y3)
Output:
False
True
False
4.h)
num1 = 30
num2 = 50
#Use ternary operator
print(num1,"is greater") if (num1 > num2) else print(num2,"is greater")
Output:
50 is greater
Result: The Demonstration of the operators in python with suitable examples
was successfully completed.
5)
Aim:To write the python program to add and multiply complex numbers.
Description:
Addition of complex number: In Python, complex numbers can be added using
+ operator.
Examples:
Input: 2+3i, 4+5i
Output: Addition is : 6+8i
Input: 2+3i, 1+2i
Output: Addition is : 3+5i
When you multiply two complex numbers, for example, a+bj and c+dj, the
resulting complex number is (ac-bd)+(ad+bc)j. Note that multiplying the
imaginary unit with itself results in the real value -1,
j*j = -1.
Program:
print("Addition of two complex numbers : ",(4+3j)+(3-7j))
print("Subtraction of two complex numbers : ",(4+3j)-(3-7j))
print("Multiplication of two complex numbers : ",(4+3j)*(3-7j))
Output:
Addition of two complex numbers : (7-4j)
Subtraction of two complex numbers : (1+10j)
Multiplication of two complex numbers : (33-19j)
Result:The python program to add and multiply complex numbers was
successfully executed.
6)
Aim:To write the python program to print mutiplication table of a given
number.
Description:
A multiplication chart is a table that shows the products of two numbers.
Usually, one set of numbers is written on the left column and another set is
written as the top row. The products are listed as a rectangular array of
numbers. Multiplication is repeated addition.
Program:
# Multiplication table (from 1 to 10) in Python
num = 12
# To take input from the user
# num = int(input("Display multiplication table of? "))
# Iterate 10 times from i = 1 to 10
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
Output:
12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120
Result: python program to print mutiplication table of a given number was
successfully completed
7)Aim:To write the python program to define a function with multiple return
values.
Description:
In Python, you can return multiple values by simply separating them with
commas in the return statement. In Python, comma-separated values are treated
as tuples, even without parentheses, unless the syntax requires them. Therefore,
the function in the example above returns a tuple.
Program:
def name():
return "John","Armin"
# print the tuple with the returned values
print(name())
# get the individual items
name_1, name_2 = name()
print(name_1, name_2)
Output:
('John', 'Armin')
John Armin
Result: The python program to define a function with multiple return values
was successfully completed.
8)Aim:To write the python program to define a function using default
arguments.
Description:
Default arguments in Python represent the function arguments that will be used
if no arguments are passed to the function call. The default arguments are
represented as argument_name = value in the function definition. Default
arguments in Python can be used with keyword and positional arguments.
Program:
def add_numbers( a = 7, b = 8):
sum = a + b
print('Sum:', sum)
# function call with two arguments
add_numbers(2, 3)
# function call with one argument
add_numbers(a = 2)
# function call with no arguments
add_numbers()
Output:
Sum: 5
Sum: 10
Sum: 15
Result: The python program to define a function using default arguments was
successfully executed.
9)Aim:To write the python program to find the length of the string without
using any library functions.
Description:
In Python, you can find the length of a string using the len() function. For
example: Python code example:- my_string = "Hello, World!" length_of_string
= len(my_string) print(length_of_string) This will output the length of the
string, which in this case is 13.
Program:
#take user input
string = 'Hello'
count = 0
for i in string:
count+=1
print(count)
Output:
5
Result: The python program to find the length of the string without using any
library functions was successfully completed.
10)Aim:The program to check if the substring is present in a given string or
not.
Description:
In Python, you can easily check if a substring is present in a given string using
the in operator. The in operator is used to test whether a particular value
(substring) exists within a sequence.
In Python, you can check python substring in string is present using an if-
else statement. The if-else statement allows you to conditionally execute
different blocks of code based on whether the condition is true or false.
Program:
text = "Geeks welcome to the Geek Kingdom!"
if "Geek" in text:
print("Substring found!")
else:
print("Substring not found!")
if "For" in text:
print("Substring found!")
else:
print("Substring not found!")
Output:
Substring found!
Substring not found!
Result: The program to check if the substring is present in a given string or not
was successfully completed.
11)Aim:The program to perform the given operations on a list:
1)addition 2)insertion3)slicing.
Description:
Addition:
Basic list operations in Python include performing basic arithmetic on the
numbers contained within a list, accessing elements of an existing list,
replacing elements of a list, rearranging elements of a list, concatenating
multiple lists together, and duplicating specific entries in a list.
Insertion:
Now we can insert an element in between the list using the inbuilt function of
Python list operation insert()
Slicing:
This method is used to print a section of the list. Which means we can display
elements of a specific index.
Python
print("The elements of list in the range of 3 to 12 are:\n",my_list[3:12])
You can also try this code with Online Python Compiler
Run Code
Using the slicing operator, we have sliced elements from range of 3 to 12 in the
my_list. Hence the above code would print elements whose index lies between
the range 3 to 12.
Program:
Python
my_list.insert(5,30)
print("The list after insert() operator is: \n",my_list)
ADDITION
myList = [1, 2, 3, 'EduCBA']
myList.append(4)
myList.append(5)
myList.append(6)
for i in range(7, 9):
myList.append(i)
print(myList)
Output;
[1,2,3,‘EduCBA’,4,5,6 ]
INSERTION
myList = [1, 2, 3, 'EduCBA' ]
myList.insert(3, 4)
myList.insert(4, 5)
myList.insert(5, 6)
print(myList)
Output:
[1,2,3,4,5,6,‘EduCBA’]
SLICING
myList = [1, 2, 3, 'EduCBA']
print(myList[:4])
print(myList[2:])
print(myList[2:4])
print(myList[:])
Output:
[1,2,3,’EduCBA’]
[3,’EduCBA’]
[3,’EduCBA’]
[1,2,3,’EduCBA’]
Result:The pyhton program to perform addition,insertion and slicing
operations was successfully executed.
12)Aim:The program to perform any 5 built-in functions by taking any list.
Description:
Built-in functions are similar to operation codes in that they perform operations
on data you specify. Built-in functions can be used in expressions.
Additionally, constant-valued built-in functions can be used in named
constants. These named constants can be used in any specification.
globals() Returns the current global symbol table as a dictionary
hasattr() Returns True if the specified object has the specified attribute
(property/method)
hash() Returns the hash value of a specified object
help() Executes the built-in help system
Programs:
a)integer = -20
print('Absolute value of -40 is:', abs(integer))
Output:
Absolute value of -20 is : 20
b)all values true
k = [1, 3, 4, 6]
print(all(k))
Output:
True
c)x = 10
y = bin(x)
print (y)
Output:
Ob1010
d)string = "Hello World."
array = bytes(string, 'utf-8')
print(array)
Output:
b Hello World
e)x = 8
print(callable(x))
Output:
False
Result: The program to perform any 5 built-in functions by taking any list was
successfully executed.
13)Aim:The program to create tuples(name,age,address,college) for at least
two members and concatenate the tuples and print the concatenated tuples.
Description:
The tuples are concatenated to create a nested tuple using the , operator and
assigned to the variable res. Here, the + operator is used to concatenate two
tuples and create a new tuple. Finally, the result is printed using the print()
function and string concatenation using the + operator.
Program:
# Python3 code to demonstrate working of
# Ways to concatenate tuples
# using + operator
# initialize tuples
test_tup1 = (1, 3, 5)
test_tup2 = (4, 6)
# printing original tuples
print("The original tuple 1 : " + str(test_tup1))
print("The original tuple 2 : " + str(test_tup2))
# Ways to concatenate tuples
# using + operator
res = test_tup1 + test_tup2
# printing result
print("The tuple after concatenation is : " + str(res))
Output :
The original tuple 1 : (1, 3, 5)
The original tuple 2 : (4, 6)
The tuple after concatenation is : (1, 3, 5, 4, 6)
Result: The program to create tuples(name,age,address,college) for at least two
members and concatenate the tuples and print the concatenated tuples was
executed.
14)Aim:The program to count the number vowels in a string (no control flow
allowed).
Description:
Step 1: Take a string from the user and store it in a variable.
Step 2: Initialize a count variable to 0.
Step 3: Use a for loop to traverse through the characters in the string.
Step 4: Use an if statement to check if the character is a vowel or not and
increment the count variable if it is a vowel.
Program:
#take user input
String = input('Enter the string :')
count = 0
#to check for less conditions
#keep string in lowercase
String = String.lower()
for i in String:
if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':
#if True
count+=1
#check if any vowel found
if count == 0:
print('No vowels found')
else:
print('Total vowels are :' + str(count))
Output:
Enter the string :PrepInsta
Total vowels are :3
Result:The program to count the number of vowels in a string was
successfully executed.
15)Aim:The program to check if a given key exists in a dictionary or not.
Description:
One common way to check if a key exists in a Python dictionary is by using
the try/except block. This method involves trying to access the value of the key
in question and catching a KeyError if it doesn't exist. In this example, we're
attempting to access the value of the key 'pear' in the dictionary my_dict.
Program:
# Create a dictionary 'd' with key-value pairs.
d = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
# Define a function 'is_key_present' that takes an argument 'x'.
def is_key_present(x):
# Check if 'x' is a key in the dictionary 'd'.
if x in d:
# If 'x' is present in 'd', print a message indicating that the key is present.
print('Key is present in the dictionary')
else:
# If 'x' is not present in 'd', print a message indicating that the key is not
present.
print('Key is not present in the dictionary')
# Call the 'is_key_present' function with the argument 5 to check if 5 is a key
in the dictionary.
is_key_present(5)
# Call the 'is_key_present' function with the argument 9 to check if 9 is a key
in the dictionary.
is_key_present(9)
Output:
Key is present in the dictionary
Key is not present in the dictionary
Result:The program to check if a given key exists in a dictionary or not was
successfully completed.
17)Aim:The program to sum all the items in a given dictionary.
Description:
Adding Values Using the setdefault() Method
In this method, we use the setdefault() method to add multiple values to a key.
If there is a particular key already present in the dictionary, then this function
adds the values passed to the key.
Program:
# Python3 Program to find sum of
# all items in a Dictionary
# Function to print sum
def returnSum(myDict):
list = []
for i in myDict:
list.append(myDict[i])
final = sum(list)
return final
# Driver Function
dict = {'a': 100, 'b': 200, 'c': 300}
print("Sum :", returnSum(dict))
Output:
Sum : 600
Result: The program to sum all the items in a given dictionary was successfully
executed.
19)Aim:The program to print each line of a file in reverse order.
Description:
User must enter a file name.
The file is opened using the open() function and all lines are stored in a list.
reversed() function produces a reverse iterator.
All the lines are then printed in reverse order using a for loop and rstrip()
function strips all the blank spaces from the end of the line.
Program:
# Open the file in write mode
f1 = open("output1.txt", "w")
# Open the input file and get
# the content into a variable data
with open("file.txt", "r") as myfile:
data = myfile.read()
data_1 = data[::-1]
# Now we will write the fully reverse
# data in the output1 file using
# following command
f1.write(data_1)
f1.close()
Output:
Result: The program to print each line of a file in reverse order was
successfully completed.
20)Aim:The program to compute the number of characters,words and lines in a
file.
Description:
Calculate the character count by using the len() function on the content string
and assign it to char_count. Calculate the word count by splitting the content
string at whitespace characters using the split() method, and then use the len()
function on the resulting list. Assign the result to word_count.
Program:
# Function to count number of characters, words, spaces and lines in a file
def counter(fname):
# variable to store total word count
num_words = 0
# variable to store total line count
num_lines = 0
# variable to store total character count
num_charc = 0
# variable to store total space count
num_spaces = 0
# opening file using with() method
# so that file gets closed
# after completion of work
with open(fname, 'r') as f:
# loop to iterate file
# line by line
for line in f:
# incrementing value of num_lines with each
# iteration of loop to store total line count
num_lines += 1
# declaring a variable word and assigning its value as Y
# because every file is supposed to start with a word or a character
word = 'Y'
# loop to iterate every
# line letter by letter
for letter in line:
# condition to check that the encountered character
# is not white space and a word
if (letter != ' ' and word == 'Y'):
# incrementing the word
# count by 1
num_words += 1
# assigning value N to variable word because until
# space will not encounter a word can not be completed
word = 'N'
# condition to check that the encountered character is a white space
elif (letter == ' '):
# incrementing the space
# count by 1
num_spaces += 1
# assigning value Y to variable word because after
# white space a word is supposed to occur
word = 'Y'
# loop to iterate every character
for i in letter:
# condition to check white space
if(i !=" " and i !="\n"):
# incrementing character
# count by 1
num_charc += 1
# printing total word count
print("Number of words in text file: ", num_words)
# printing total line count
print("Number of lines in text file: ", num_lines)
# printing total character count
print('Number of characters in text file: ', num_charc)
# printing total space count
print('Number of spaces in text file: ', num_spaces)
# Driver Code:
if _name_ == '_main_':
fname = 'File1.txt'
try:
counter(fname)
except:
print('File not found')
Output:
Number of words in text file: 25
Number of lines in text file: 4
Number of characters in text file: 91
Number of spaces in text file: 21
Result: The program to compute the number of characters,words and lines in a
file was successfully executed.
21)Aim:The program to create,display,append,insert and reverse the order of
the items in the array.
Description:
By using the numpy library we can easily create an array using the numpy.
array() method. In the same way, we can also append an element to the array
using the numpy. append() method.
The for-loop method is a simple and intuitive approach to reverse an array in
Java. The idea is to iterate through half of the array and swap the
corresponding elements from both ends. This process continues until the
middle is reached, resulting in a reversed array.
Program:
import numpy as np
# Input list
my_list = [4, 5, 6, 7, 8, 9]
# Convert the list to a 1D numpy array
my_array = np.array(my_list)
# Reverse the order of the array
reversed_array = my_array[::-1]
# Convert the reversed array to a list
reversed_list = reversed_array.tolist()
# Print the reversed list
print(reversed_list)
Output:
[9, 8, 7, 6, 5, 4]
Result: The program to create,display,append,insert and reverse the order of
the items in the array was successfully completed.
22)Aim:The program to add,tranpose and multiply two matrices.
Description:
The sum of the matrices is obtained using the for loop, using nested list
comprehension, and by using the zip().
To transpose a matrix in Python, FOR loop is used. Each element of the matrix
is iterated and placed at the respective place in the transpose.
Matrix multiplication in Python involves taking the dot product of rows from
the first matrix with columns from the second. This operation requires the
number of columns in the first matrix to be equal to the number of rows in the
second for it to be valid.
Program:
# Program to multiply two matrices using nested loops
# 3x3 matrix
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
# 3x4 matrix
Y = [[5,8,1,2],
[6,7,3,0],
[4,5,9,1]]
# result is 3x4
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
# iterate through rows of X
for i in range(len(X)):
# iterate through columns of Y
for j in range(len(Y[0])):
# iterate through rows of Y
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print(r)
Out put:
[114, 160, 60, 27]
[74, 97, 73, 14]
[119, 157, 112, 23]
Result: The program to add,tranpose and multiply two matrices was
successfully completed.
25)Aim:The program to demonstrate Numpy arrays creation using array()
funtion.
Description:
In Python, you can create new datatypes, called arrays using the NumPy
package. NumPy arrays are optimized for numerical analyses and contain only
a single data type. You first import NumPy and then use the array() function
to create an array. The array() function takes a list as an input.
Program:
import numpy as np
# create a list named list1
list1 = [2, 4, 6, 8]
# create numpy array using list1
array1 = np.array(list1)
print(array1)
Output:
[2 4 6 8]
Result: The program to demonstrate Numpy arrays creation using array()
funtion was successfully completed.
26)Aim:The program to demostrate use of ndim,shape,size,dtype.
Description:
ndim represents the number of dimensions (axes) of the ndarray. shape is a
tuple of integers representing the size of the ndarray in each dimension. size is
the total number of elements in the ndarray. It is equal to the product of
elements of the shape.
Program:
import numpy as np
a = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]])
print("Dimension of the given Ndarray=",a.ndim)
print("Shape of the given Ndarray=",a.shape)
print("Size of the given Ndarray=",a.size)
print("Data Type of given Ndarray=",a.dtype)
print("Size of each element in Ndarray=",a.itemsize)
Output:
Dimension of the given Ndarray= 3
Shape of the given Ndarray= (2, 2, 3)
Size of the given Ndarray= 12
Data Type of given Ndarray= int64
Size of each element in Ndarray= 8
Result: The program to demostrate use of ndim,shape,size,dtype was
successfully completed.
28)Aim:The program to find min,max,sum,cumulative sum of array.
Description:
The cumulative sum of elements in an array is a new array where each
element represents the sum of all preceding elements, including itself, in
the original array.
One approach to find the maximum and minimum element in an array is to
first sort the array in ascending order. Once the array is sorted, the first
element of the array will be the minimum element and the last element of the
array will be the maximum element.
Program:
my_set = {5, 2, 8, 1, 9, 2, 18}
# Find the maximum and minimum values
maximum = max(my_set)
minimum = min(my_set)
#display the resulting value
print("Maximum:", maximum)
print("Minimum:", minimum)
Output
Maximum: 18
Minimum: 1
Result:The program to find min,max,sum,cumulative sum of array was
successfully executed.
30)Aim:Selecting any two columns from the above data frame,and observe
the change in one attribute with respect to other attribute with scatter and plot
operations in matplotlib.
Description:
we are using basic method that utilizes the Pandas library to create a
DataFrame named ‘df’ from a dictionary of employee data, and then selects
and displays only the ‘Name’ and ‘Qualification’ columns
from the DataFrame.
This example uses the pandas library to create a DataFrame ‘df’ from a
dictionary of employee data. It then selects and displays all rows while
extracting columns 2 to 4 (Age, Address, and Qualification) using DataFrame
slicing based on column indices.
Program:
import pandas as pd
import matplotlib.pyplot as plt
# Data to be plotted
data = [["New York", 8.6, 20],
["Chicago", 2.7, 20],
["Los Angeles", 3.9, 20],
["Philadelphia", 1.5, 20],
["Houston", 2.1, 20]]
# Form DataFrame from data
df = pd.DataFrame(data, columns=["City", "Population(million)",
"Year(2020)"])
# Plot unstacked multiple columns such as population and year from
DataFrame
df.plot(x="City", y=["Population(million)", "Year(2020)"],
kind="bar", figsize=(10, 10))
# Display plot
plt.show()
Output:
Result: The Selecting any two columns from the above data frame,and
observe the change in one attribute with respect to other attribute with scatter
and plot operations in matplotlib was suucessfully completed.