1. Print variables
You can print variables using the print() function by including the variable name inside the
parentheses. Here's an example:
name = "Alice"
print("Hello, " + name + "!")
This will print Hello, Alice! to the console.
2. Use formatted strings
Formatted strings allow you to embed expressions inside string literals. This can be useful for
including variables in your output. Here's an example:
name = "Alice"
age = 25
print(f"Hello, {name}! You are {age} years old.")
This will print Hello, Alice! You are 25 years old. to the console.
3. Use escape sequences
Escape sequences allow you to print special characters, such as new lines, tabs, and
backslashes. Here's an example:
print("Hello,\nworld!")
This will print:
Hello,
world!
4. Print lists
You can print lists using the print() function. Here's an example:
numbers = [1, 2, 3, 4, 5]
You can print variables using the print() function by including the variable name inside the
parentheses. Here's an example:
name = "Alice"
print("Hello, " + name + "!")
This will print Hello, Alice! to the console.
2. Use formatted strings
Formatted strings allow you to embed expressions inside string literals. This can be useful for
including variables in your output. Here's an example:
name = "Alice"
age = 25
print(f"Hello, {name}! You are {age} years old.")
This will print Hello, Alice! You are 25 years old. to the console.
3. Use escape sequences
Escape sequences allow you to print special characters, such as new lines, tabs, and
backslashes. Here's an example:
print("Hello,\nworld!")
This will print:
Hello,
world!
4. Print lists
You can print lists using the print() function. Here's an example:
numbers = [1, 2, 3, 4, 5]