Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating strings in python without spaces [duplicate]

How can I print my strings so that there are no spaces between each output.

name_input = str(input("Please enter your name"))
name_input = name_input.strip()
name_input = name_input.lower()
first_letter = name_input[0]
first_space = name_input.find(" ")
last_name = name_input[first_space:]
last_name_3 = last_name[0:4]
random_number = random.randrange(0,999)
print("*********************************************")
print("Username Generator")
print("*********************************************")
print(first_letter + last_name_3, random_number)`

Incorrect output: b fir 723

what I require: bfir723

like image 941
Bayyls Avatar asked Oct 18 '25 14:10

Bayyls


1 Answers

use the separator parameter to the print function, to remove the space by passing in an argument with no space.

Like this:

print(first_letter, last_name_3, random_number, sep='')

The default separator is a space. Specification is here:

https://docs.python.org/3/library/functions.html#print

like image 149
coding_carebear Avatar answered Oct 21 '25 01:10

coding_carebear



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!