+ 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
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")
+ 2
You need to do string interpolation.
sentence = lambda name: f"Hello, {name}"
+ 2
You can also put 2 strings together:
sentence = lambda name: "Hello, " + name
+ 1
Why do I have to do that? In the course they don't do it.
+ 1
You will learn about putting strings together and about string interpolation in the Python Intermediate course.
+ 1
But in the course they do it without the f
+ 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.
+ 1
And with f you can do interpolation?
+ 1
Thank you! With + it's working
+ 1
Can you give me the answer of (address=__________) in python
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."
0
What do you mean Mohammad?