Output Statements
The Output Statement is use for, if we want to provide any output statement then we need the Print() statement. in this print() statement we have some methods also there.
1st Method:
Print() without any agreement and the result will be a new line created.
Ex1:
Print()
a new line was created...# but not showing anything. we take one more example.
Ex2:
Result:
krishna
devi
2nd Method:
Print() without some agreement like any agreement or any escape characters we can use.
Ex1:
Result:
krishna
Ex2:
Result:
krishna
gopi ravi
3rd Method:
in this method, we can assign multiple assignments with multiple values.
Ex:
Result:
10 20 30 40 # result with spaces
now going to focus on some attributes
above example if we take a,b,c,d = 10,20,30,40 and we print(), then result we will be 10 20 30 40, in this result we adsorb that result will be space in-between numbers. but we don't want to be space in between results. We want to do something else on the final result. then in this type of scenario sep attribute will help.
Ex:
Result:
10:20:30:40 # result with colon
now we use one more attribute called end
if we use the end attribute then it will add attribute characters within the same line.
Ex:
Result:
Krishna
ravi
gopi
Ex:
Result:
Krishnaravigopi
Ex:
Result:
Krishna,ravi,gopi,
now just one more example with sep and end attributes.
Ex:
Result:
10:20:30***40:50:60
70@@80$$
some more examples on output statements
Ex:
Result:
krishnagopi
krishna gopi
Print statement take any type of object will take without any error
EX:
Result:
[10, 20, 30, 40] (10, 20, 30, 40) {40, 10, 20, 30} [10, 20, 30, 40]
print() statement with replacement operator {}
Ex:
Result:
Hi, krishna you have taken 10,000 on this sis bank.
Ex:
one more option in index type
Result:
Hi, krishna you have taken 10,000 on this sis bank.
Ex:
one more option in keyword type
Result:
Hi, krishna you have taken 10,000 on this sis bank.
but the almost all-time first one is mostly used and recommended.
print() statement with formatted string
%i = signed decimal value
%d = signed decimal value
%f = signed float value
%s= signed string value
Ex:
a value = 10 #Result
Ex:
a value = 10,b value = 20,c value = 30 #Result
Ex:
hello krishna your marks [60, 72, 86, 42, 79] #Result
replacement operator {} and formatted string are working both same looks like. but some advantage of formatted string checks on below
Ex:
number value =789.2345 #Result
number value =789.234500
but if we add like below on 2nd line
the result will be number value =789.23
so this is the advantage. we can collect an accurate number as per our requirement.
Post a Comment