How to add / between spaces in a date [duplicate] - python

This question already has answers here:
Replacing instances of a character in a string
(17 answers)
Closed 4 years ago.
How can I take a string that returns it in a list with " / " between them, like dates.
for example
Taking 5,11,2013 and the output be 5/11/2013

Use str.replace() ?
date = '11,12,2019'
print(date.replace(',', '-'))
>> 11-12-2019

Related

Is there a better way to print a certain number of whitespaces with print() based on the length of the printed output? [duplicate]

This question already has answers here:
Printing Lists as Tabular Data
(20 answers)
Python spacing and aligning strings
(7 answers)
Create nice column output in python
(22 answers)
How to Print "Pretty" String Output in Python
(5 answers)
Closed 1 year ago.
I'm trying to create something like this as terminal output:
VALUE A VALUE B INT C
alpha bravo 69420
charlie delta 69421
echo foxtrot 69422
I have a snippet of code from a different script to print the correct number of spaces (in this example, make it so that there are spaces after the printed value until col 64.)
print(header)
for f in files:
fLen = len(f)
fiLen = (fLen - 64)
finLen = (fiLen - fiLen - fiLen)
print(f+" "*(fiLen))
I'm not sure how to:
Get this same operation done with less operation to keep it "pythonic",
Scale this to multiple columns (like to automatically generate a lot more rows of that example output.

Workings for addition calculator is not showing [duplicate]

This question already has answers here:
How do I put a variable’s value inside a string (interpolate it into the string)?
(9 answers)
Closed 1 year ago.
print ("Naomi's Calculator!")
print("Addition")
value_1= 10
value_2= 15
working= (value_1 "+" value_2)
print(working)
result=(value_1+value_2)
print(result)
working variable is wrong, i want the result to be like 10+15
value_1 and value_2 are int, you need to convert them in string if you want to see that output for working variable.
working = (str(value_1)+"+" +str(value_2))

Curious about the function of ~in the following code [duplicate]

This question already has answers here:
The tilde operator in Python
(9 answers)
Closed 1 year ago.
pd_selftest = pd_selftest[pd_selftest['SICCD'] != 0]
pd_selftest = pd_selftest[~pd_selftest['SICCD'].isnull()]
I'd like to know what the function of the ~ is in the above code.
That's the bit-wise invert or not operator. So, it returns only those lines where the SICCID column is not null. I would probably use the word not in this case.

How to print values side by side? [duplicate]

This question already has answers here:
Print new output on same line [duplicate]
(7 answers)
Closed 5 years ago.
How can i print dictionary values side by side ?
Could you please assists me ?
Use print(hashstring, end = ' ')

Python 3 - convert mathematical action to integer [duplicate]

This question already has answers here:
Math operations from string [duplicate]
(8 answers)
Closed 6 years ago.
I have a string with a formula 5 - 3, and I need to get the result in integer. How could I do that?
use eval function:
eval("5 - 3") # 2
test = "5-3"
print(eval(test))
Gives 2

Categories

Resources