Linked Questions
23 questions linked to/from Why are parentheses optional when using print in Python 2.7?
12
votes
6
answers
67k
views
Concatenating values in a print statement [duplicate]
I have the string "Bob" stored in a variable called name.
I want to print this:
Hello Bob
How do I get that?
Let's say I have the code
name = "Bob"
print ("Hello", name)
This gives
('Hello', 'Bob')...
5
votes
3
answers
33k
views
brackets around print in python [duplicate]
I have this line of code in python
print 'hello world'
against
print ('hello world')
can someone tell me the difference between the two?
I used it in a a simple code
var = 3
if var > 2:
...
1
vote
1
answer
437
views
print a function by default in Python 2.7.11? [duplicate]
The other day I accidentally wrote
print("a function?")
in my Python 2.7.11 console and was quiet astonished that it would work instead of throwing an error. I assumed, there was an implicit
from ...
-1
votes
1
answer
641
views
Brackets on Print Statements in Python on Stack Overflow [duplicate]
Why, in Python examples on Stack Overflow is there usually no brackets on 'print' statements? Is this because the version used is Python 2?
0
votes
0
answers
373
views
Printing variables in strings in Python 2.7.10 [duplicate]
I have a small, dumb Python script I created for a course I found that teaches Python for Python 3.4.1. I have Python 2.7.10. I have software on my computer that depends on 2.7.10, and will cause a ...
0
votes
0
answers
47
views
What is the purpose of print()[] syntax in Python? [duplicate]
Today I randomly realized you can add an index after print() in python, which behaves pretty much as if it was applied to a list passed as a parameter to print.
>>> sublists = [[['a'],['b'],[...
0
votes
0
answers
31
views
Why can't print be assigned to foo in python 2? [duplicate]
Why does the python 2 code throw error on assigning print to foo whereas python 3 doesn't?
Python 2
>>> foo = print
File "<stdin>", line 1
foo = print
^
...
622
votes
5
answers
594k
views
python: return, return None, and no return at all -- is there any difference?
Consider these three functions:
def my_func1():
print "Hello World"
return None
def my_func2():
print "Hello World"
return
def my_func3():
print "Hello World"
...
130
votes
18
answers
501k
views
Getting SyntaxError for print with keyword argument end=' '
When I try this code:
if Verbose:
print("Building internam Index for %d tile(s) ..." % len(inputTiles), end=' ')
I get a SyntaxError claiming that end=' ' is invalid syntax.
Why does ...
5
votes
2
answers
5k
views
Why can print("string", object) give different results than print(object)?
I have defined this class:
class Point():
def __init__(self,x,y):
self.x = x
self.y = y
def __str__(self):
return "Point x: {0}, Point y: {1}".format(self.x, self.y)
...
2
votes
5
answers
11k
views
Python prints the parenthesis from the function
Simple code but a a bit of an odd issue. Python tends to print the brackets and coma in the print function. This only happens in row 5 and row 7 but not for the last row. Any idea what's wrong?
e.g. ...
2
votes
5
answers
205
views
significance of using print() in python
What is the difference between using print() and not using it.
For example, say a = ("first", "second", "third'), what is the difference between
print (a[0] a[2])
and
a[0] a[2]
?
2
votes
0
answers
7k
views
Python " ".join() syntax error [duplicate]
I haven't done much with Python, but the code-academy course has seemed to give me some enjoyment however when I have taken my project to the actual python compiler I get an error compiling. Highly ...
0
votes
2
answers
912
views
SyntaxError near "print"? [closed]
can anybody please tell me why this is giving me syntax error in idle?
def printTwice(bruce):
print bruce, bruce
SyntaxError: invalid syntax
1
vote
2
answers
960
views
Regex Search and replace including rest of the line in brackets
I have some python code with many lines like this:
print "some text" + variables + "more text and special characters .. etc"
I want to modify this to put everything after print within brackets, like ...