I have a very simple question to some of you, as I'm new to this,
in the def f3, how do I put spaces between the 4 strings,
and in def f5, how do I remove the space after the "Hi name," I want the , to come right after without a spacce
#๐ Helo
31 messages ยท Page 1 of 1 (latest)
@supple python
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
!d str.join
str.join(iterable)```
Return a string which is the concatenation of the strings in *iterable*. A [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError) will be raised if there are any non\-string values in *iterable*, including [`bytes`](https://docs.python.org/3/library/stdtypes.html#bytes) objects. The separator between elements is the string providing this method.
Format-strings
Creating a Python string with your variables using the + operator can be difficult to write and read. F-strings (format-strings) make it easy to insert values into a string. If you put an f in front of the first quote, you can then put Python expressions between curly braces in the string.
>>> snake = "pythons"
>>> number = 21
>>> f"There are {number * 2} {snake} on the plane."
"There are 42 pythons on the plane."
Note that even when you include an expression that isn't a string, like number * 2, Python will convert it to a string for you.
Thank you, let me try this real quick
The other option for f5 is to concatenate (add) the strings together so you don't have a space
By default, print adds a space between arguments
So if you make it 1 string: "Hello" + "World" you don't get the extra space
how exactly do you do that
can anyone help me if you can? i made a channel when i try to set ....
!e
print("Hello" + "World")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
HelloWorld
oh wait makes sense
Another option is to tell print not to add a space between arguments
!e
# Set the separator to an empty string instead of a space
print("Hello", "World", sep="")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
HelloWorld
And Grote's solution is to use an f-string:
string_a = "Hello"
string_b = "World"
print(f"{string_a}{string_b}")
Which allows you to put a variable's value directly in a string (note the f before the ")
in f5 when I do, 'Hi' + name it's working but when I do it with the other string it doesn't work
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.