Print Commend
Print Commend
1. Basic `print()`:
print("Hello, World!")
print(42)
x = 10
print(x)
a, b = 5, 10
print("a + b =", a + b)
Allows you to insert variables directly in strings using the `f` prefix.
name = "Alice"
age = 25
4. String Concatenation:
last_name = "Doe"
6. Escape Characters:
Handle special characters like quotes and slashes with escape sequences (`\`).
print("Path: C:\\Users\\Name")
7. End Parameter:
By default, `print()` ends with a newline (`\n`). You can change this using the `end` parameter.
print("World!")
You can specify how to separate multiple items in a `print()` statement using the `sep` parameter.
9. Print to a File:
You can direct the output of `print()` to a file using the `file` parameter.
price = 19.99
quantity = 3
You can directly print lists, dictionaries, and other data structures.
my_list = [1, 2, 3, 4]
print(my_list)
print(my_dict)
You can control the number of decimal places when printing floating-point numbers.
pi = 3.14159
for i in range(5):
import time
time.sleep(2)
print(" Done!")
name = "John"
age = 30