Hi all this is my task one with simple questions
1.Printing “Hello, world!”
concept: the print() function is used to print the output.
print("Hello, world!")
Explanation:
Anything inside quotes is a string. Python prints it exactly as it is.
2.Printing variable
Concept: Variables store values.
name = "Syed Jafer"
print(name)
Explanation:
Instead of printing text directly, we store it in a variable and print it.
- Printing Multiple Variables with Labels Concept: Combine text with variables.
name = "Syed Jafer"
age = 20
city = "Chennai"
print("Name:", name)
print("Age:", age)
print("City:", city)
Explanation:
Comma , automatically adds a space between values.
4.Using f-strings (Modern Method)
Concept: Clean and readable formatting.
print(f"Name: {name}, Age: {age}, City: {city}")
Explanation:
f allows inserting variables inside {} directly.
- Concatenating Strings Concept: Joining strings using +.
greeting = "Hello"
target = "world"
print(greeting + " " + target)
Explanation:
We manually add a space " " between words.
6.Printing Multiple Lines
Concept: Each print() gives a new line.
print("Line1")
print("Line2")
print("Line3")
Explanation:
Every print statement moves to the next line automatically.
- Printing Quotes Inside String Concept: Mixing quotes safely.
print('He said, "Hello, world!"')
Explanation:
Use single quotes outside to allow double quotes inside.
- Printing Backslashes (Raw String) Concept: Avoid escape sequences.
print(r"C:\Users\Name")
Explanation:
r means raw string → Python ignores escape characters.
9.Printing Expression Result
Concept: Python can calculate inside print().
print(5 + 3)
Explanation:
Python evaluates the expression first → prints 8.
- Printing with Hyphen Concept: Custom separators.
print("Hello-world")
Explanation:
Hyphen is just a character inside the string.
- Printing on Same Line Concept: Control line ending.
print("Hello", end=" ")
print("world!")
Explanation:
end=" " prevents newline and adds a space.
- Printing Boolean Value Concept: Boolean values (True/False).
is_active = True
print(is_active)
Explanation:
Python prints boolean values directly.
- Repeating a String Concept: String multiplication.
print("Hello " * 3)
Explanation:
"*" is used to multiple with 3 repeats the string three times.
- Using Variable in Sentence Concept: Dynamic text using variables.
temperature = 22.5
print(f"The temperature is {temperature} degrees Celsius.")
Explanation:
Value is inserted inside the sentence.
- Using .format() Method Concept: Old-style formatting.
print("Name: {}, Age: {}, City: {}".format(name, age, city))
Explanation:
{} are placeholders filled by .format().
- Rounding Numbers Concept: Formatting decimals.
pi = 3.14159
print("The value of pi is approximately {:.2f}".format(pi))
Explanation:
:.2f → rounds to 2 decimal places.
- Alignment (Left & Right) Concept: Formatting width.
print("{:<10}{:>10}".format("left", "right"))
Explanation:
<10 → left aligned
10 → right aligned
Top comments (0)