DEV Community

Jagadishwaran G
Jagadishwaran G

Posted on

PYTHON – PRINT EXERCISES

How do you print the string “Hello, world!” to the screen?

print("Hello World")

How do you print the value of a variable name which is set to “Syed Jafer” or Your name?

name ="Jagadish"
print(name)

How do you print the variables name, age, and city with labels “Name:”, “Age:”, and “City:”?

name = "Tom"
age=25
city = "Chennai"

print("My name is {}, and my age is {}, Currently leaveing in City is {}".format(name, age, city))

How do you use an f-string to print name, age, and city in the format “Name: …, Age: …, City: …”?

name = "Tom"
age=25
city = "Chennai"
print(f"Name : {name}, Age :{age},City : {city}")

How do you concatenate and print the strings greeting (“Hello”) and target (“world”) with a space between them?

greeting = "Hello"
target = "world"
print(greeting,target)

How do you print three lines of text with the strings “Line1”, “Line2”, and “Line3” on separate lines?

print("""Welcome"
To python free class
from Kaniyam""")

How do you print the string He said, "Hello, world!" including the double quotes?

print(' He said, "Hello, world!"')

How do you print the string C:\Users\Name without escaping the backslashes?

print(r"C:\Users\jagadishwarang\Downloads")

How do you print the result of the expression 5 + 3?

a = 5
b = 3
print(a+b)

How do you print the strings “Hello” and “world” separated by a hyphen -

print("Hello", "world", sep="-")

How do you print the string “Hello” followed by a space, and then print “world!” on the same line?

print("Hello world")

How do you print the string “Hello ” three times in a row?

print("Hello" * 3)

Top comments (0)