Output Variables

In Python, you can output variables using the print() function. You can combine strings and variables using the + operator, or use formatted strings for more complex output.

Basic Output:

Python
x = "Python"
print("Learning " + x)  # Output: Learning Python

Formatted Strings (f-strings):

Python 3.6+ allows you to use f-strings for a more concise and readable way to format strings:

Python
name = "John"
age = 30
print(f"Hello, my name is {name} and I am {age} years old.")
# Output: Hello, my name is John and I am 30 years old.

Using format() method:

Python
name = "Alice"
age = 25
print("Name: {}, Age: {}".format(name, age))
# Output: Name: Alice, Age: 25