#๐Ÿ”’ Helo

31 messages ยท Page 1 of 1 (latest)

supple python
#

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

snow spearBOT
#

@supple python

Python help channel opened

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.

sweet nebula
#

!d str.join

snow spearBOT
#

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.
white vine
#

I'd use an f-string

#

!f-string

snow spearBOT
#
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.

white vine
#

for the f5 that is

#

for the f3 join makes sense

supple python
#

Thank you, let me try this real quick

sweet nebula
#

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

topaz plank
#

can anyone help me if you can? i made a channel when i try to set ....

sweet nebula
#

!e

print("Hello" + "World")
snow spearBOT
sweet nebula
#

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="")
snow spearBOT
sweet nebula
#

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 ")

supple python
#

in f5 when I do, 'Hi' + name it's working but when I do it with the other string it doesn't work

sweet nebula
#

Show the code that does not work

#

!code

snow spearBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

supple python
#

!close

snow spearBOT
#
Python help channel closed

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.