This content originally appeared on DEV Community and was authored by Ganesh Balaraman
- 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 = "syed Jafer"
print (name)
How do you print the variables name, age, and city with labels “Name:”, “Age:”, and “City:”?
print ( "name:" , name , "age:" , age , "city:" , city )
How do you use an f-string to print name, age, and city in the format “Name: …, Age: …, City: …”?
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?
print("hello " + "world")
How do you print three lines of text with the strings “Line1”, “Line2”, and “Line3” on separate lines?
print("line1\nline2\nline3")
How do you print the string He said, "Hello, world!" including the double quotes?
print (' "hello , world!" ')
How do you print the string C:\Users\Name without escaping the backslashes?
print(r"C:\users\name")
How do you print the result of the expression 5 + 3?
print (5+3)
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 value of a boolean variable is_active which is set to True?
this = True
print(this)
How do you print the string “Hello ” three times in a row?
print("hello * 3")
How do you print the sentence The temperature is 22.5 degrees Celsius. using the variable temperature?
temperature = 22.5
print("the temperature is " + str(temperature) + " degrees celcius.")
How do you print name, age, and city using the .format() method in the format “Name: …, Age: …, City: …”?
print("name: {} , age:{} , city:{}". format(name,age,city))
This content originally appeared on DEV Community and was authored by Ganesh Balaraman
Ganesh Balaraman | Sciencx (2024-07-13T05:14:15+00:00) Task 1: print exercises. Retrieved from https://www.scien.cx/2024/07/13/task-1-print-exercises/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.