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".
Related
This question already has answers here:
How can I print a single backslash?
(4 answers)
Closed 2 years ago.
I use print() function to use like this:print("\")and i get an exception. Tell me how to slove it. Thks
Use \\ instead.
Actually, \ is a special character and you have to escape it.
print("\\") # print a single "\" character
Use:
print("\\")
instead of print("\")
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'
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"
This question already has answers here:
Using print() (the function version) in Python2.x
(3 answers)
Closed 6 years ago.
I am currently coding a slot-like game, and everything seems to work besides this one thing:
File "/Users/r/Desktop/Game.py", line 36
print(one, end = " ")
^
SyntaxError: invalid syntax
Does anyone know how to fix this?
Are you trying to pass a Boolean for the second parameter to print?
In that case you want print(one, end == ' ')
This question already has answers here:
How to define a function that would check if a string have whitespaces after the sentence is finished?
(2 answers)
Closed 8 years ago.
I am trying to write a function to check for trail whitespace, but not to remove the spaces. but i have no idea of how to do that. can somebody teach me?
thank you
Using str.endswith:
>>> 'with trailing space '.endswith(' ')
True
>>> 'without trailing space'.endswith(' ')
False