Python
Python
Title :- Demonstrate about fundamentals data types in python programming (i.e int, float,
complex , bool and string types)
Program:-
Output :-
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 :-
Output :-
v) Ternary operator :-
Program :-
output :-
output :-
num = 25
else:
if num % 2 == 0:
print("Number is even")
else:
print("Number is odd")
if num == 25:
else:
Output :-
Program:-
count = 0
print("Count:", count)
count += 1
print("Fruit:", fruit)
Output:-
Program :-
print()
Output :-
Program:-
Output :-
Output:-
Program:-
Output:-
Program:-
Output:-
Program :-
Output:-
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 :-
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():
a = 10
b = 20
print("variable a:", a)
print("variable b:", b)
return a+b
print(myfunction())
Output:-
Program :-
c=30
d=40
def myfunction():
print("variable c:", c)
print("variable d:", d)
myfunction()
Output:-
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()
Program :-
Implantation of write () method:
file=open("C:\\Users\\Admin\\File2.txt.txt","w")
file.close()
file=open("C:\\Users\\Admin\\File2.txt.txt","r")
print(file.read())
file.close()
Output :-
Implantation of writelines () method:
Output :-