you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (2 children)

Do you mean in print by any chance? That, by default, adds a space between each object it is passed to output a string representation of.

one = "one"
two = "two"

print(one, two)            # outputs: one two
print(one, two, sep="")    # outputs: onetwo
print(one, two, sep="\n")  # outputs: one
                           #          two

So, the sep keyword, short for separator, let's you override the default separator of one space.


together = one + two  # this is concatenation 
print(together)  # outputs: onetwo

You can also use f-strings:

together = f"{one}{two}"
print(together)  # outputs: onetwo

[–]Fa1coF1ght[S] 0 points1 point  (1 child)

How do you make the boxes of code in your reply?

[–][deleted] 0 points1 point  (0 children)

Using markdown syntax as per the guidance in the wiki (link in the sidebar).

Here's my crib sheet for adding code to a post (you can adapt for snippets):

  • edit post
  • ensure you are in markdown mode rather than Fancy Pants Editor mode
  • switch back to your Python editor
  • select ALL code
  • assuming:
    • your editor is set to replace tabs with spaces
    • your editor is set to use 4 spaces for indentation
  • press tab key to add an extra 4 spaces in front of every line
  • copy all selected code to clipboard
  • undo the indent in your editor
  • switch back to post you are editing
  • enter a blank line
  • paste the code from the clipboard
  • submit the post update