Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Unsure about Python Expression Syntax

I've been asked the following question and I'm unsure as I was able to enter all of them (in IDLE) then use the print() function to return the given values successfully with no errors.



Thanks in advance.
(Oct 29, 2021 10:20 PM)Poojar102 Wrote:  I've been asked the following question and I'm unsure as I was able to enter all of them (in IDLE) then use the print() function to return the given values successfully with no errors.



Thanks in advance.

I think the answer they are looking for is d, the reason is because it has the semicolon at the end. Although there is no reason why this won't run it is generally discouraged in python to use a semicolon at the end of a line as opposed to compiled languages.
https://www.askpython.com/python/example...-in-python
https://stackoverflow.com/questions/8236...on-snippet
https://towardsdatascience.com/stop-usin...3ce4ff1086

Hey there,
If I have helped you or if you just enjoy my posts, please consider donating bitcoin to me 1DpL2kcxuidEsjt2MMN2AYufcVoXbi3v2X

[Image: FtwuQgr.gif]
(Oct 30, 2021 04:33 AM)tux1 Wrote:  I think the answer they are looking for is d, the reason is because it has the semicolon at the end. Although there is no reason why this won't run it is generally discouraged in python to use a semicolon at the end of a line as opposed to compiled languages.
https://www.askpython.com/python/example...-in-python
https://stackoverflow.com/questions/8236...on-snippet
https://towardsdatascience.com/stop-usin...3ce4ff1086

Yeah that's why I'm confused because all of the options are viable. Thanks for the detailed response though man, appreciate it!


(Oct 30, 2021 04:33 AM)tux1 Wrote:  I think the answer they are looking for is d, the reason is because it has the semicolon at the end. Although there is no reason why this won't run it is generally discouraged in python to use a semicolon at the end of a line as opposed to compiled languages.
https://www.askpython.com/python/example...-in-python
https://stackoverflow.com/questions/8236...on-snippet
https://towardsdatascience.com/stop-usin...3ce4ff1086

Congratulations on your 11,000ᵗʰ post btw
I don't understand it, either. Python is not C. tux has linked to the explanations of why Python doesn't need semicolons.

When I need to show the end of some process/function in Python for whatever reason, I just comment "# END OF FUNCTION". :/
[Image: chain.png]
Python ignores the semicolon for some reason. There was once when I was doing a lot of Java and moved down to Python, still had the habit of putting semicolons, and found out it doesn't stop the code from running, lol. But it's definitely D, without a doubt, as the other ones are perfectly fine syntax-speaking.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[C] by aeiroDec 21, 2019 05:47 PM 9 314 Dec 21, 2019 05:47 PM
Last Post: Emp3hack
[Python] by Wic12Sep 23, 2019 09:27 PM 1 163 Sep 23, 2019 09:27 PM
Last Post: datguy.dev