Expt 2
Expt 2
1. To print variable
We 1st assign the value ti the variable ,and then we use the print() function to display the
values of variable on the screen.
#taking input from user
a = (int(input("Enter a number:")))
#print variable program
print("THE number is :", a)
Output:- Enter a number:7
THE number is : 7
2. To delete Variable
We create a variable and then use the del statement to delete it.
a = 35
print("Element deleted:", a)
del a
Output:- Element deleted: 35
4. Multiline Statements
You can use a backslash \ at the end of a line to indicate that the statement continues on the
next line.
#4. Multiline Statements
sum = 6 + \
5 + \
2
print("Sum = ",sum)
Output:- Sum = 13
5. Comments
Single-line comments start with the # symbol. Everything after the # on that line is treated as
a comment.
#4. Multiline Statements
6) Multiline Comment
We can use triple-quotes (or) to create a multiline string that is not assigned to any variable,
effectively serving as a multiline comment.
*** this is
A multiline
Command***
7) String Operations
1) Concatenation: You can combine strings using the + operator.
Local Variables: Local variables are defined within a function and have local scope which means
they can only be accessed from within that specific function.
#Local variable
def loc():
var = 9
print(var)
loc()
Output:-
Datatype1: <class 'int'>
Datatype2: <class 'float'>
Datatype3: <class 'str'>
Datatype4: <class 'list'>
Datatype5: <class 'list'>
Datatype6: <class 'complex'>