+ 1

Getting rid of spaces in output

Is there a way to get rid of the spaces in the output of this code? BDay_Month=random.randint(1,12) BDay_Day=random.randint(1,31) BDay_Year=random.randint(2000,2010) if BDay_Month==4 or 6 or 9 or 11: if BDay_Day==31: BDay_Day==30 if BDay_Month==2: if BDay_Day>=29: if BDay_Year%4==0: BDay_Day=29 else: BDay_Day==28 print("Born:",BDay_Month,"/",BDay_Day,"/", BDay_Year) The output of this code looks like MM / DD / YYYY, How can I get the output look like MM/DD/YYYY?

20th Jul 2020, 4:12 AM
•—• • •-• ••• —- -•
•—• • •-• ••• —- -• - avatar
6 ответов
+ 3
The f or F in front of strings tell Python to look at the values inside {} and substitute them with the variables values if exists.
20th Jul 2020, 4:29 AM
Akash
Akash - avatar
+ 3
As 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 had said, both string formatting and/or string concatenation can solve this problem. However, I think the easiest way to solve this (with the fewest modifications) is to use "sep" argument in "print" function. For example, just add [sep=""] at the tail of your print statement: print("Born: ", BDay_Month, "/", BDay_Day, "/" , BDay_Year, sep="") *Edit: "sep" is a separator used in print function, and its default value is " "(a space), and that is why you saw those annoying blanks.
20th Jul 2020, 4:57 AM
李立威
+ 2
When you ask Question don't write code in question.There is a + icon where you writes your question just click on it and then click on Insert Code and insert your Code.Then peoples will be able to understand your Code easily.
20th Jul 2020, 4:18 AM
Akash
Akash - avatar
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 What does the f in the first option do? Removing it causes the contents inside the quotation marks to be directly printed. Is the f like a combination of r/raw input and .format?
20th Jul 2020, 4:24 AM
•—• • •-• ••• —- -•
•—• • •-• ••• —- -• - avatar
+ 1
Got it, thanks guys
20th Jul 2020, 4:30 AM
•—• • •-• ••• —- -•
•—• • •-• ••• —- -• - avatar
+ 1
I am happy to help.
20th Jul 2020, 4:32 AM
Akash
Akash - avatar