+ 3

Where is the bug?

Why it outputs an error? sentence = lambda name: "Hello,", name print(sentence("Jakob")) https://sololearn.com/compiler-playground/chE9gTsNZeHl/?ref=app

18th Aug 2025, 7:39 AM
Jakob
Jakob - avatar
13 Antwoorden
+ 2
Jakob you're probably confusing concatenation with print arguments. in print you can do print('Hello', name) but remember, print is a function. 'Hello' and name are arguments passed to it, so they are separated by comma. the real concatenation is being done by the print function. if you want, you can modify your lambda function to: sentence = lambda name: print("Hello", name) sentence("Jakob")
18th Aug 2025, 9:29 AM
Bob_Li
Bob_Li - avatar
+ 2
You need to do string interpolation. sentence = lambda name: f"Hello, {name}"
18th Aug 2025, 8:03 AM
Mila
Mila - avatar
+ 2
You can also put 2 strings together: sentence = lambda name: "Hello, " + name
18th Aug 2025, 8:06 AM
Mila
Mila - avatar
+ 1
Why do I have to do that? In the course they don't do it.
18th Aug 2025, 8:39 AM
Jakob
Jakob - avatar
+ 1
You will learn about putting strings together and about string interpolation in the Python Intermediate course.
18th Aug 2025, 8:47 AM
Mila
Mila - avatar
+ 1
But in the course they do it without the f
18th Aug 2025, 9:00 AM
Jakob
Jakob - avatar
+ 1
I don't remember if it was there or not) But you should know that every language has interpolation. Interpolation is a simple way to add a variable directly to a string. For example, you have a variable that contains not a string, but a number or bool.
18th Aug 2025, 9:03 AM
Mila
Mila - avatar
+ 1
And with f you can do interpolation?
18th Aug 2025, 12:20 PM
Jakob
Jakob - avatar
+ 1
Thank you! With + it's working
18th Aug 2025, 12:30 PM
Jakob
Jakob - avatar
+ 1
Can you give me the answer of (address=__________) in python
18th Aug 2025, 1:00 PM
Mohammad Athif Athif
Mohammad Athif Athif - avatar
0
Jakob strings with f before the quotation marks are called f-strings. you can directly put your variables inside {} and they will be converted to str and concatenated. for your code, instead of using +, you can do this instead: sentence = lambda name, age: f"Hello {name} you are {age} years old."
18th Aug 2025, 12:56 PM
Bob_Li
Bob_Li - avatar
0
What do you mean Mohammad?
18th Aug 2025, 1:02 PM
Jakob
Jakob - avatar