This question already has answers here:
Using quotation marks inside quotation marks
(12 answers)
Closed 3 years ago.
Say for example I want to print ‘I can fly’, including the quotations.
How to write the print statement?
you could do this:
print(" 'hi' ")
output: 'hi'
Related
This question already has answers here:
Remove text between () and []
(8 answers)
Best way to replace multiple characters in a string?
(16 answers)
How to replace multiple substrings of a string?
(28 answers)
Closed last month.
I have string like this.
a="what is[hags] your name?"
I want delete [hags] from string!
output:
a="what is your name?"
This question already has answers here:
How to fix syntax error when printing a string with an apostrophe in it? [closed]
(6 answers)
Closed 3 years ago.
bob = input('How old are you? ')
print('You're', bob)
It's giving me syntax error because im using ' for you're. Whats the correct way of handling sentences with ' in them?
There are at least two ways to do this:
Use " for your string: "You're".
Escape the single quote: 'You\'re".
This question already has answers here:
Remove all whitespace in a string
(14 answers)
Closed 3 years ago.
This is my string "INDUSTRIAL, PARKS, PROPERTY"
I want to delete the spaces trailing parks, property.
I want the output as "INDUSTRIAL,PARKS,PROPERTY"
For your example you can do:
strr = "INDUSTRIAL, PARKS, PROPERTY"
','.join(strr.split(', '))
Otherwise if you have something like:
strr = "INDUSTRIAL, PARKS, PROPERTY"
','.join([s.strip() for s in strr.split(', ')])
This question already has answers here:
Why doesn't calling a string method (such as .replace or .strip) modify (mutate) the string?
(3 answers)
Closed 3 years ago.
I have the txt file below and I want the remove the "+" if there is a + in front of the number.
+905061459318
+905458507534
+905437335094
I have tried almost all of the solutions that exist in Stackoverflow but still, I cannot remove the + from the line.
The code is here.
with open("numbers.txt") as f:
lines = [line.rstrip('\n') for line in open("numbers.txt")]
for line in lines:
if line.startswith("+"):
line.replace("+","")
else:
pass
You already have line.rstrip('\n'). Make that line.rstrip('\n').lstrip('+').
This question already has answers here:
How can I fill out a Python string with spaces?
(14 answers)
Closed 5 years ago.
Is there a custom way of padding lines of text in python, I am using the escape characters "\t", but I wonder if there is an alternative.
for example
print('My Name is:')
print('Rambo')
print('Mambo')
Output:
.My Name is:
.....Rambo
..Mambo
Try using:
print('{:>15}'.format('My Name is:'))
Refer for examples:
PyFormat
Write a simple function for yourself.
def p(a,b):
print(" "*a + b)
p(1,"while")
This should return:" while"