0% found this document useful (0 votes)
13 views3 pages

Interview Questions-21-10-24

Uploaded by

POOJA DHAKANE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Interview Questions-21-10-24

Uploaded by

POOJA DHAKANE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Interview Questions===>

Q. Explain with Example sep, end, %d, %f, %s and format, f" "

ANS:

sep:
The sep parameter in Python's print() function specifies the separator between the
arguments passed to print(). By default, the separator is a space ' ', but you can
change it to any character or string by setting the sep argument.

Example:=>
print('The','Kiran','Academy')
#The Kiran Academy

print('The','Kiran','Academy',sep="*")
#The*Kiran*Academy

end:
In Python, the end parameter in the print() function specifies what should be
printed at the end of the output. By default, it is set to "\n", which means it
adds a newline after printing the output. You can change it to any string or
character you prefer.

Example=>
print('Hello','Pooja')
#Hello Pooja

print("Hello","Pooja",end="!!!!")
#Hello Pooja!!!!

%d:
In Python, %d is a format specifier used in strings to format integers. It is part
of the older string formatting method (also known as the % formatting style). %d
specifically formats the value as a decimal (integer).

print("Enter your 3 subjects marks:==>")


English=int(input("Enter marks for English Subject:"))
Marathi=int(input("Enter marks for Marathi Subject:"))
Hindi=int(input("Enter marks for Hindi Subject:"))

Sum = English+Marathi+Hindi

print("Sum of three subjects i.e. %d , %d and %d is %d"%


(English,Marathi,Hindi,Sum))

#Enter your 3 subjects marks:==>


# Enter marks for English Subject:90
# Enter marks for Marathi Subject:96
# Enter marks for Hindi Subject:95
# Sum of three subjects i.e. 90 , 96 and 95 is 281

%f:
In Python, %f is a format specifier used to format floating-point numbers. It is
part of the old-style string formatting (using the % operator). %f formats a number
as a floating-point value with six decimal places by default.

radius=eval(input("Enter the Radius for Circle=>"))


pi = eval(input("Enter PI value=>"))
area = pi*(radius**2)

print("Area of circle for radius %0.1f with PI value %0.2f is %0.3f"%


(radius,pi,area))
#Enter the Radius for Circle=>3
# Enter PI value=>3.14
# Area of circle for radius 3.0 with PI value 3.14 is 28.260

print("Area of circle for radius {} with PI value {} is {}".format(radius, pi,


area))
#Enter the Radius for Circle=>3
Enter PI value=>3.14
Area of circle for radius 3.0 with PI value 3.14 is 28.260
Area of circle for radius 3 with PI value 3.14 is 28.26

%s:
In Python, %s is a format specifier used to format strings. It is part of the old-
style string formatting (using the % operator), and it can convert any object to a
string.

name=input('Enter your Name=>')


last_name=input("Enter your Last Name=>")
school_name=input("Enter your School Name=>")
print("My name is %s and last name is %s. My School name is %s"%
(name,last_name,school_name))
print("My name is {} and last name is {} and My School Name is
{}".format(name,last_name,school_name))

#Enter your Name=>Pooja


# Enter your Last Name=>Dhakane
# Enter your School Name=>Modern School
# My name is Pooja and last name is Dhakane. My School name is Modern School
# My name is Pooja and last name is Dhakane and My School Name is Modern School

format():
In Python, the format() method is used for string formatting. It allows you to
create a formatted string by inserting values into placeholders marked by curly
braces {}. It's a more modern and flexible alternative to the old % formatting
style.

name = "Pooja"
weight = 56
height = 5.3
print("my name is {}. My weight={} and Height={}".format(name,weight,height))
#my name is Pooja. My weight=56 and Height=5.3

print("my name is {n}. My weight={w} and


Height={h}".format(n=name,w=weight,h=height))
#my name is Pooja. My weight=56 and Height=5.3

print("my name is {n}. My weight={w} and


Height={h}".format(w=weight,h=height,n=name,))
#my name is Pooja. My weight=56 and Height=5.3

f"":
In Python, f"" (also called f-strings or formatted string literals) is a concise
and powerful way to format strings. Introduced in Python 3.6, f-strings allow you
to embed expressions inside string literals by prefixing the string with f or F and
placing expressions inside curly braces {}.
x = 10
y = 5
print(f"{x} + {y} = {x + y}")
#10 + 5 = 15

You might also like