Python Q and A: Part 1

Posted on Aug. 17, 2020 by Ted Martin

In a print statement, what happens if you leave out one of the parentheses, or both?

- Leaving off the right parentheses will continue to await its closing. It will not close the execution of the print statement.

- Leaving off the left parentheses will do the same thing.

- Leaving off both parentheses will yield a syntax error.

If you try to print a string, what happens if you leave out one of the quotation marks, or both?

- Leaving off the left quotation mark will yield a "EOL while scanning string literal". EOL stands for end of line.

- Leaving off the right quotation mark will yield the same syntax error.

- Leaving off both quotation marks will yield a NameError as not defined. Python expects a variable with a value without quotation marks but unless you have a one word print statement and coincidently have a variable with the same letters as the desired print statement, the NameError is your gift :)

You can use a minus sign to make a negative number like -2. What happens if you put a plus sign before a number? What about 2++2?

- A plus sign before a number yields the positive integer. A double addition sign - e.g. 2++2 - yields the same value as 2 + 2; namely, '4'.

In math notation, leading zeros are okay, as in 02. What happens if you try this in Python?

- You receive a "Syntax Error": "leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers"

What happens if you have two values with no operator between them?

- You will receive a Syntax Error.

 

Share post

0 comments

There are no comments yet.

Add a new comment