0% found this document useful (0 votes)
12 views20 pages

Python

Uploaded by

Amit Jha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
12 views20 pages

Python

Uploaded by

Amit Jha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 20

Experiment No – 01

Title :- Demonstrate about fundamentals data types in python programming (i.e int, float,
complex , bool and string types)

Program:-

Output :-

Conclusion :- we have studies about fundamental data types


Experiment No – 02

Title :- Demonstrate the following Operators in Python with suitable examples. i) Arithmetic
Operators ii) Relational Operators iii) Assignment Operator iv) Logical Operators v) Bit
wise Operators vi) Ternary Operator vii) Membership Operators viii) Identity Operators
Program :-
i) Arithematic operators :-
Program :-

Output :-

ii) Relational Operators :-


Program :-
Output :-

iii) Logical operator :-


Program:-

Output :-

iv) Bit-wise operator :-


Program :-
Output :-

v) Ternary operator :-
Program :-

output :-

vi) Membership operator :-


Program:-
Output :-

vii) Identity operators :-


Program:-

output :-

Conclusion :- we have studies about operators how it works


Experiment No– 03
Title :- Demonstrate the following Conditional statements in Python with suitable examples. i) if
statement ii) if else statement iii) if – elif – else statement
Program:-

num = 25

if num > 50:

print("Number is greater than 50")

elif num > 30:

print("Number is greater than 30 but less than or equal to 50")

else:

print("Number is less than or equal to 30")

if num % 2 == 0:

print("Number is even")

else:

print("Number is odd")

if num == 25:

print("Number is exactly 25")

else:

print("Number is not 25")

Output :-

Conclusion:- we have studies about if, if-else and if-else-if statement


Experiment No – 04
Title :- Demonstrate the following Iterative statements in Python with suitable examples.
i) while loop ii) for loop

Program:-

# Example using while loop

count = 0

while count < 5:

print("Count:", count)

count += 1

# Example using for loop

fruits = ["apple", "banana", "cherry"]

for fruit in fruits:

print("Fruit:", fruit)

Output:-

Conclusion:- we have studies about while loop and for loop


Experiment No – 05
Title :- Write Python programs to print different Patterns: (Any Patterns) Example like
*
**
***
****
*****

Program :-

n = int(input("Enter the number of rows"))

for i in range(0, n):

for j in range(0, i + 1):

print("* ", end="")

print()

Output :-

Conclusion :- we have studies python program to print different pattern


Experiment No - 06
Demonstrate the following functions/methods which operates on strings in Python with
Title :- suitable examples: i) len( ) ii) strip( ) iii) rstrip( ) iv) lstrip( ) v) find() vi) rfind( ) vii) index( )
viii) rindex() ix) count( ) x) replace( ) xi) split( ) xii) join() xiii) upper( ) xiv) lower( ) xv)
swapcase( ) xvi) title( ) xvii) capitalize( ) xviii) startswith() xix) endswith()

Program:-

Output :-

Conclusion:- we have studies various operation on String


Experiment No – 07
Demonstrate the following functions/methods which operates on lists in Python with suitable
Title :- examples: i) list( ) ii) len( ) iii) count( ) iv) index ( ) v) append( ) vi) insert( ) vii) extend()
viii) remove() ix) pop( ) x) reverse( ) xi) sort() xii) copy( ) xiii) clear( )
Program:-

Output:-

Conclusion :- we have studies various operation on List


Experiment No – 08
Demonstrate the following functions/methods which operates on tuples in Python with
Title :-
suitable examples: i) len( ) ii) count( ) iii) index( ) iv) sorted( ) v) min ( ) vi)max( ) vii)
cmp( ) viii) reversed( )

Program:-

Output:-

Conclusion :- we have studies various operation on tuples


Experiment No – 09
Title :- Demonstrate the following functions/methods which operates on sets in Python with
suitable examples: i) add( ) ii) update( ) iii) copy( ) iv) pop( ) v) remove( ) vi)discard( ) vii)
clear() viii) union() ix) intersection( ) x) difference()

Program:-

Output:-

Conclusion :- we have studies various operation on set


Experiment No -10
Title :- Demonstrate the following functions/methods which operates on dictionary in
Python with suitable examples: i) dict( ) ii) len( ) iii) clear( ) iv) get( ) v) pop() vi)popitem( )
vii) keys( ) viii) values() ix) items( ) x) copy( ) xi) update( )

Program :-

Output:-

Conclusion :- we have studies various operation on dictionary


Experiment No – 11
Title :- Write a Python program to return multiple values at a time using a return statement

Program :-

def multiple_values():

a=1

b=2

c=3

return a, b, c

x, y, z = multiple_values()

print("Value of x:", x)

print("Value of y:", y)

print("Value of z:", z)

Output :-

Conclusion :- we have studies about return statement in python


Experiment No -12
Title :- Write a Python program to demonstrate Local and Global variables

Local variables :-
- A local variable is defined within a specific function or block of code. It can only be accessed by the
function or block where it was defined, and it has a limited scope.
- In other words, the scope of local variables is limited to the function they are defined in and
attempting to access them outside of this function will result in an error.
- Always remember, multiple local variables can exist with the same name.

Program :-

def myfunction():

#declaring local varibles a,b

a = 10

b = 20

print("variable a:", a)

print("variable b:", b)

return a+b

print(myfunction())

Output:-

Conclusion :- we have studies about local variables


Global variables :-
- A global variable can be accessed from any part of the program, and it is defined
outside any function or block of code. It is not specific to any block or function

Program :-

c=30

d=40

def myfunction():

# accessing variables c & d inside the function

print("variable c:", c)

print("variable d:", d)

myfunction()

Output:-

Conclusion :- we have studies about global variables in python


Experiment No – 13
Title :- Write a Python program to demonstrate read() and readline() methods in File handling

Program:-
Implantation of readline() method:

file=open("C:\\Users\\Admin\\File1.txt.txt","r")
print("First Line:",file.readline())
print("Second Line:",file.readline())
print("Third Line:",file.readline())
file.close()

Output:-
Implantation of read() method:

file=open("C:\\Users\\Admin\\File1.txt.txt","r")

print(file.read())

file.close()

Conclusion :- We have studied the implementation of read() and readline() methods in


file handling by using python
Experiment No – 14
Title :- Write a Python program to demonstrate write() and writelines() methods in File
handling

Program :-
Implantation of write () method:

file=open("C:\\Users\\Admin\\File2.txt.txt","w")

file.write("Hello All, Hope you enjoying Python")

file.close()

print("Data written to the file..")

file=open("C:\\Users\\Admin\\File2.txt.txt","r")

print(file.read())

file.close()

Output :-
Implantation of writelines () method:

Output :-

Conclusion :- we have studies about implementation of write() and writelines() in file


handling using python

You might also like