Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111112

Re: How well do you know Python?

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: How well do you know Python?
Date 2016-07-05 10:36 +0200
Organization None
Message-ID <mailman.91.1467707774.2295.python-list@python.org> (permalink)
References <CAPTjJmoZobGYDh8jWDPPWQqoN-gid+-HUp9-dtKX_Vp=BgHc+w@mail.gmail.com> <nlfrhl$bq1$1@ger.gmane.org>

Show all headers | View raw


Chris Angelico wrote:

> After some discussion with a Ruby on Rails programmer about where Ruby
> ends and where Rails begins (and it's definitely not where I'd have
> expected... Rails does a ton of monkey-patching, including of built-in
> types, to provide functionality that is strangely absent from the core
> language), I tried to come up with some somewhat-challenging Python
> questions. But to make them hard, I had to go a smidge more esoteric
> than the Ruby questions did.... Anyhow, see how you go. Assume Python
> 3.x unless stated.
> 
> 1) Under what circumstances can str.upper() return a string of
> different length to its input?
> 2) What exception do you get when you craft an impossible class hierarchy?
>     a. ValueError b. TypeError c. types.ClassInheritanceError d.
>     SyntaxError
> 3) What does `from __future__ import braces` do?
> 4) Which operator, removed from Python 3.0, can be reinstated with a
> 'joke' future directive?
> 5) What is the difference between the `/` and `//` operators in Python
> 2.7? In Python 3.x?
> 
> Got any other tricky questions to add?

What will 

$ cat foo.py 
import foo
class A: pass
print(isinstance(foo.A(), A))
$ python -c 'import foo'
...
$ python foo.py
...

print?

It looks like

$ python3 -c 'print({1, 2})'
{1, 2}
$ python3 -c 'print({2, 1})'
{1, 2}

will always print the same output. Can you construct a set from two small 
integers where this is not the case? What's the difference?

What happens if you replace the ints with strings? Why?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: How well do you know Python? Peter Otten <__peter__@web.de> - 2016-07-05 10:36 +0200
  Re: How well do you know Python? Steven D'Aprano <steve@pearwood.info> - 2016-07-05 20:35 +1000

csiph-web