In Python, print(f”…“) uses f-strings (formatted string literals) to directly embed variables, logic, and expressions inside a text string. Introduced in Python 3.6, the f prefix tells Python to evaluate anything inside curly braces {} at runtime. Core Syntax and Usage
Instead of using messy string concatenation + or older .format() rules, you write the f or F prefix right before the opening quote.
name = “Alice” age = 30 # The modern f-string way print(f”Hello, {name}. You are {age} years old.“) # Output: Hello, Alice. You are 30 years old. Use code with caution. Key Capabilities What is print(f”…“) – python – Stack Overflow
Leave a Reply