dangerous class neighborhood

Avi Gross avigross at verizon.net
Fri Dec 28 02:01:07 EST 2018


Short answer to a short question.

 

What does a dot (dot dot) mean in pseudocode?

 

NOTHING and EVERYTHING.

 

Longer answer:

 

I think what you see may not be what I wrote. I used three dots in a row (an ellipsis) to mean that something is left out to be filled in with something appropriate.

 

A = …

B = …

 

That was meant to mean that it does not really matter exactly what code is used. Set A equal to SOMETHING and set B equal to something.

 

As it happens, there are computer languages where that is valid code. Python turns out to be one of them!

 

 

>>> A=...

>>> A

Ellipsis

 

In python you can often use “pass” in some contexts like:

 

>>> if 1: pass

>>> def name():

                Pass

 

These don’t do anything except serve as a placeholder and should be replaced later. There are cases where you can write something like this:

 

>>> x = 5

>>> if x > 7:

                pass

else:

                print(x)

 

                

5

 

But although that works, you could simply use a NOT or invert the condition to say:

 

>>> if not (x > 7):

                print(x)

 

                

5

>>> if (x <= 7):

                print(x)

 

                

5

 

Well “…” can also be used in modern versions of python although it may not be novice-level material. It can serve as a placeholder in things like this:

 

>>> def name(x,y,z): pass

 

>>> name(1,2,3)

>>> name(1,3)

Traceback (most recent call last):

  File "<pyshell#25>", line 1, in <module>

    name(1,3)

TypeError: name() missing 1 required positional argument: 'z'

>>> name(1,...,3)

 

You can see the third positional argument is still the third in this example:

 

>>> def name(x,y,z): print(x,z)

 

>>> name(1,...,3)

1 3

 

So what is the middle argument in this case?

 

>>> def name(x,y,z): print(x,y,z)

 

>>> name(1,...,3)

1 Ellipsis 3

>>> name(...,...,3)

Ellipsis Ellipsis 3

>>> name(...,...,...)

Ellipsis Ellipsis Ellipsis

 

I suspect that generally the intent is to eventually fill in the missing argument.

 

Here is a related anomaly. The single underscore has multiple uses but one is to say you are throwing away something.

 

>>> a, _, c = (1, "who cares", 3)

>>> a

1

>>> _

'who cares'

>>> c

3

 

But what I used the same variable name multiple times?

 

>>> _, _, c = (1, "who cares", 3)

>>> _

'who cares'

>>> c

3

 

To be fair, any variable used repeatedly in that context keeps only the rightmost assignment. But there is an idiom of using just an underscore to mean you don’t care about that and want something else whose name may be made meaningful.

 

>>> _, _, LastName = ("John", "J.", "Doe")

>>> LastName

'Doe'

 

So, my apologies. I won’t use … even in pseudocode.

 

 

From: Abdur-Rahmaan Janhangeer <arj.python at gmail.com> 
Sent: Friday, December 28, 2018 12:30 AM
To: Avi Gross <avigross at verizon.net>
Cc: Python <python-list at python.org>
Subject: Re: dangerous class neighborhood

 

btw what does

 

A = .

 

above means? the dot?

Abdur-Rahmaan Janhangeer
http://www.pythonmembers.club <http://www.pythonmembersclub>  | https://github.com/Abdur-rahmaanJ
Mauritius



More information about the Python-list mailing list