Why does the Python repl print different things for None? [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Today I was playing with a Python dict and I found something weird:
>>> print {}.get('non-existant-key')
>>> a = {}.get('non-existant-key')
>>> print a
None
>>>
Why does the repl print an empty space with the first print and "None" after taking the step of storing the value in the variable a? The thing it tries to print is the same in both cases, so why is there be a difference?

Okay, turns out it wasn't the behaviour of the Python repl, but the (for the rest excellent) bpython repl which I always use. I didn't realise I was using bpython instead of the vanilla python when I was testing this.
In the regular pyton repl it all works as expected. I'll file a bug with bpython about this.

Related

What is the purpose of "_104" in round function in python? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
In round function what is the use of _100, _104, etc.
I know that round(10.121, 1) will round the value up to 1 decimal place.
But the purpose of _104 is not getting.
I've attached two screenshots for reference.
In IPython, _109 means the output of the 109th cell execution. This implies that while you were running your IPython notebook (through VS Code), at cell execution 109, you received an output of 103. The reason why Bram above can't run print(_109) on his end is that he was either running it in a Python file/interpreter, or executing it in a fresh notebook where he hasn't run 109 cells yet, and thus the variable _109 did not exist.
Check this answer for more information: https://stackoverflow.com/a/27952661/2327379

Why is it giving me this syntax error? I’m following a tutorial. (Beginner) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
It's saying there's a syntax error (seems simple enough) but I've double-checked the video (and my brain). I don't see why it would be saying that.
Been following this tutorial and taking notes to a T (if I need to include more code let me know).
I defined "run_test" and am entering the parameters in question. Help?
You have extra opening parenthesis before ‘str(len(...))’
There should be a closing brackets for str in print statement ')' , add this and your program will work
If i am not wrong, you haven't defined the list of questions yet. If you have defined your list of questions it is probably a typing error in your code. If there is the full code under the tutorial you are doing then i would compare my code to the code from the tutorial.

Equality operator (==) has no effect [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am currently following through a book (Python Crash Course), and have just been introduced to the '==' equality operator.
In the book, it shows setting a variable and checking whether it is equal to itself (using ==). See below.
Also tried numerical comparisons and having the same issue as outlined below.
car = "bmw"
car == "bmw"
This is providing no output and PyCharm is telling me 'car == "bmw" has no effect. Book is telling me it should be responding "True" as I am checking the variable which I have literally JUST set.
Try:
car = "bmw"
print(car == "bmw")
Or type your code directly in the console. Just running your script like that won’t produce anything, because you don’t do anything with the comparison.

error while writing print statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
A very simple question but I am struggling.
I am learning through CBT Nuggets and in one video teacher says we use print statement from python 3 as that is more advanced. It means it can take parameters.
jim#jim-beam-VirtualBox:~/Documents/python$ cat 4_IO.py
print('Hellow World!'
print('Hello','World','!')
jim#jim-beam-VirtualBox:~/Documents/python$ python 4_IO.py
File "4_IO.py", line 2
print('Hello','World','!')
^
SyntaxError: invalid syntax
jim#jim-beam-VirtualBox:~/Documents/python$
What is this error and why I am getting and not the teacher when I using the same python version 2.7.10
jim#jim-beam-VirtualBox:~/Documents/python$ python --version
Python 2.7.10
jim#jim-beam-VirtualBox:~/Documents/python$
Your help would be really appreciated.
Its because you forgot the brace on the first line.
print('Hellow World!'
^--brace here

SyntaxError: invalid syntax (print function) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
>>> x=[]
>>> for i in range(10):
x.append(i)
print(x)
SyntaxError: invalid syntax
I'm working with Python 3.5. I can't seem to get the print function working when it's not part of a loop. "print" gets highlighted as the source of the syntax error, but I can't seem to isolate the cause of the error. It prints perfectly well when part of a while or for loop. It's probably caused by a really silly oversight, and I would really appreciate if somebody could point it out.
If you are typing in console, you need to hit enter twice to end that statement. Which in your case, what you did is, you wrote print inside for without indentation. So it will show syntax error.

Categories

Resources