[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.programming

First Program with Python!

anitagoyal571

2/9/2016 2:11:00 PM

Python is a very powerful high-level, object-oriented programming language.Python has a very easy-to-use and simple syntax, making it the perfect language for someone trying to learn computer programming for the first time. Python is an interpreted language. Interpreter is a program that converts the high-level program we write into low-level program that the computer understands. Click here to find the difference between interpreter and compiler.. This tutorial is based on Python 3 and all the examples in this tutorial have been tested and verified in Python.

Start learning Python from basics to advance levels here...
https://goo...

21 Answers

Richard Heathfield

2/9/2016 2:30:00 PM

0

On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
> Python is a very powerful high-level, object-oriented programming
> language.Python has a very easy-to-use and simple syntax, making
> it the perfect language for someone trying to learn computer
> programming for the first time. Python is an interpreted language.
> Interpreter is a program that converts the high-level program we
> write into low-level program that the computer understands.

That sounds more like a compiler to me. An interpreter is a program that
interprets instructions written in a high-level language and carries
them out straight away. It's rather like the difference between an
interpreter who whispers a constant stream of translated information
into a delegate's ear, and a translator who takes a batch of original
Pliny or Tacitus and turns it into deathless English prose. If we take
BASIC, for example:

10 PRINT "HELLO"
20 END

the interpreter's job is to convince the computer to print HELLO
on the screen RIGHT NOW, whereas the compiler's job is to create a
program in some other language that expresses the same intent as the
BASIC program, a program that can be executed at some later time
/without/ a further need for using the interpreter. These are very
distinct tasks, and your claim about a "low-level program that the
computer understands" sounds very much more like a poorly-expressed
misunderstanding of a compiler than it sounds like an interpreter.

> Click here to find the difference between interpreter and compiler.

Are you sure you know?

> This tutorial is based on Python 3 and all the examples in this
> tutorial have been tested and verified in Python.
>
> Start learning Python from basics to advance levels here...

Why should we trust a programming tutorial by someone who takes such
little care over their grammar? (I'm not saying we shouldn't. I'm just
asking the question.) What makes your tutorial worth reading?

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Ben Bacarisse

2/9/2016 2:35:00 PM

0


> On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
<stuff I've cut>

Richard Heathfield <rjh@cpax.org.uk> writes:
> [...] What makes your tutorial worth reading?

The link is to a company selling online courses. It's commercial spam,
pure and simple.

--
Ben.

Richard Heathfield

2/9/2016 7:06:00 PM

0

On 09/02/16 14:35, Ben Bacarisse wrote:
>
>> On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
> <stuff I've cut>
>
> Richard Heathfield <rjh@cpax.org.uk> writes:
>> [...] What makes your tutorial worth reading?
>
> The link is to a company selling online courses. It's commercial spam,
> pure and simple.

Thanks. I like to give people the benefit of the doubt and assume that
they are posting in comp.programming because they want to talk about
programming. On the other hand, I'm not naive about it, and I realise
that spam is commonplace (which is why I carefully snipped the link).

I framed my reply in such a way as to invite the poster into a
discussion, knowing that a strong possibility existed that they would
not do so but nevertheless giving them the opportunity, just in case.

Had I followed the link, no doubt I would have discovered what you
discovered, but I never follow links in Usenet unless I have some prior
experience of the poster actively contributing to discussions.

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Öö Tiib

2/10/2016 12:32:00 AM

0

On Tuesday, 9 February 2016 16:30:19 UTC+2, Richard Heathfield wrote:
> On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
> > Python is an interpreted language.
> > Interpreter is a program that converts the high-level program we
> > write into low-level program that the computer understands.
>
> That sounds more like a compiler to me.

Good catch. AFAIK Python is simply a programming language without
requirement that it *must* be interpreted. There even are some
JIT-compiling Python 3 implementations like PyPy and Pyston.

Öö Tiib

2/10/2016 12:55:00 AM

0

On Tuesday, 9 February 2016 21:06:26 UTC+2, Richard Heathfield wrote:
> On 09/02/16 14:35, Ben Bacarisse wrote:
> >
> >> On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
> > <stuff I've cut>
> >
> > Richard Heathfield <rjh@cpax.org.uk> writes:
> >> [...] What makes your tutorial worth reading?
> >
> > The link is to a company selling online courses. It's commercial spam,
> > pure and simple.
>
> Thanks. I like to give people the benefit of the doubt and assume that
> they are posting in comp.programming because they want to talk about
> programming. On the other hand, I'm not naive about it, and I realise
> that spam is commonplace (which is why I carefully snipped the link).
>
> I framed my reply in such a way as to invite the poster into a
> discussion, knowing that a strong possibility existed that they would
> not do so but nevertheless giving them the opportunity, just in case.
>
> Had I followed the link, no doubt I would have discovered what you
> discovered, but I never follow links in Usenet unless I have some prior
> experience of the poster actively contributing to discussions.

Spam that contains factual, logical and/or typographical flaws is
often constructed that way so to filter in the people who can not
spot such flaws.

Richard Heathfield

2/10/2016 9:21:00 AM

0

On 10/02/16 00:55, Öö Tiib wrote:

<snip>

> Spam that contains factual, logical and/or typographical flaws is
> often constructed that way so to filter in the people who can not
> spot such flaws.

Yet another reason to post a counter to it (without, of course,
promulgating its URL) - to filter /out/ those people who may not be able
to spot such flaws themselves, but who are able to recognise the
implications of such flaws when they are pointed out.

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Bartc

2/10/2016 2:07:00 PM

0

On 10/02/2016 00:32, Öö Tiib wrote:
> On Tuesday, 9 February 2016 16:30:19 UTC+2, Richard Heathfield wrote:
>> On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
>> > Python is an interpreted language.
>> > Interpreter is a program that converts the high-level program we
>> > write into low-level program that the computer understands.
>>
>> That sounds more like a compiler to me.
>
> Good catch. AFAIK Python is simply a programming language without
> requirement that it *must* be interpreted. There even are some
> JIT-compiling Python 3 implementations like PyPy and Pyston.
>

PyPy is such a complex implementation that probably no one knows for
sure exactly what it is.

From what I've been able to glean, PyPy is actually an interpreter (and
an even slower one than CPython), but written in such a way that
repeated execution paths (through the interpreter apparently, not the
bytecode being executed) are chosen to be JIT-compiled. So what is
JIT-compiled, I think, are parts of the interpreter, which is written in
customised version of Python. It doesn't JIT-compile the user's actual
program, AFAICT.

It's just a touch confusing.

You can tell from the language anyway that it is completely unsuitable
for normal 'straight' compilation to native code. So interpretation
would be the usual start-point.


--
Bartc

David Brown

2/10/2016 3:24:00 PM

0

On 10/02/16 15:07, BartC wrote:
> On 10/02/2016 00:32, Öö Tiib wrote:
>> On Tuesday, 9 February 2016 16:30:19 UTC+2, Richard Heathfield wrote:
>>> On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
>>> > Python is an interpreted language.
>>> > Interpreter is a program that converts the high-level program we
>>> > write into low-level program that the computer understands.
>>>
>>> That sounds more like a compiler to me.
>>
>> Good catch. AFAIK Python is simply a programming language without
>> requirement that it *must* be interpreted. There even are some
>> JIT-compiling Python 3 implementations like PyPy and Pyston.

There are few programming languages that /must/ be interpreted, or
/must/ be compiled. There are C and C++ interpreters available. And
for many traditionally interpreted languages, there are compilers for
all or part of the language. (Python is mostly byte-compiled, with the
python byte-code run in a dedicated virtual machine. Jython compiles
Python source to Java byte code and runs it on a Java virtual machine.)

The exception is for code that is not known at "compile" time, such as
creating Python code from a string - that would have to be interpreted
or JIT-compiled.

>>
>
> PyPy is such a complex implementation that probably no one knows for
> sure exactly what it is.
>
> From what I've been able to glean, PyPy is actually an interpreter (and
> an even slower one than CPython), but written in such a way that
> repeated execution paths (through the interpreter apparently, not the
> bytecode being executed) are chosen to be JIT-compiled. So what is
> JIT-compiled, I think, are parts of the interpreter, which is written in
> customised version of Python. It doesn't JIT-compile the user's actual
> program, AFAICT.

PyPy is a Python interpreter with JIT acceleration. Where possible,
Python code is used to generate C code that is then compiled (with gcc
or clang), and called from the PyPy interpreter. Some Python code
cannot sensibly be compiled in this way, and it gets interpreted.

So the user's Python code, along with the Python libraries, get
JIT-compiled.


>
> It's just a touch confusing.
>
> You can tell from the language anyway that it is completely unsuitable
> for normal 'straight' compilation to native code. So interpretation
> would be the usual start-point.
>

Certainly interpretation is the common way to handle Python code. And
static compilation is going to be a lot less efficient than dynamic or
JIT compilation. For example, consider the function:

def average(it) :
return sum(it) / len(it)

Your code could call that function with lists of integers, tuples of
floating point, a tree structure of matrix types, or anything else that
supports an iteration interface and whose elements can be added and then
divided by an integer. Clearly any general compiled version of that
function is going to involve a lot of indirect lookup to get the
required functions to operate on the types that happen to be passed to
any particular call of the function.

But if your code only ever calls the function with tuples of three
floating point numbers, it can be reduced to a few assembly instructions
to operate only on that particular type of argument. So a JIT compiled
version is going to be a great deal smaller and faster than a statically
compiled version could ever be.


Bartc

2/10/2016 4:55:00 PM

0

On 10/02/2016 15:24, David Brown wrote:
> On 10/02/16 15:07, BartC wrote:

>> From what I've been able to glean, PyPy is actually an interpreter (and
>> an even slower one than CPython), but written in such a way that
>> repeated execution paths (through the interpreter apparently, not the
>> bytecode being executed) are chosen to be JIT-compiled.

> PyPy is a Python interpreter with JIT acceleration. Where possible,
> Python code is used to generate C code that is then compiled (with gcc
> or clang), and called from the PyPy interpreter. Some Python code
> cannot sensibly be compiled in this way, and it gets interpreted.

I believe PyPy is written in RPython. That is, the interpreter for
normal Python is written in a special language called RPython, which
looks like Python but restricts those features that make it slow. That
RPython undergoes whole-program analysis to turn it into C.

So, we now still have a Python intepreter, but it's in C (a bit like the
normal CPython), but there is some extra magic in there to optimise
'hot' execution paths.

This is where it's unclear as to whether those paths are part of the
RPython interpreter, or part of the Python bytecode being executed.

I thought it was the former. But the end result is that the Python
program ends up faster (sometimes a magnitude or two faster), than
normal CPython. In which case, no will really care exactly how it works!

Unless someone is discussing whether the Python is being compiled or
interpreted...

>> You can tell from the language anyway that it is completely unsuitable
>> for normal 'straight' compilation to native code. So interpretation
>> would be the usual start-point.

> Certainly interpretation is the common way to handle Python code. And
> static compilation is going to be a lot less efficient than dynamic or
> JIT compilation. For example, consider the function:
>
> def average(it) :
> return sum(it) / len(it)
>
> Your code could call that function with lists of integers, tuples of
> floating point, a tree structure of matrix types, or anything else that
> supports an iteration interface and whose elements can be added and then
> divided by an integer. Clearly any general compiled version of that
> function is going to involve a lot of indirect lookup to get the
> required functions to operate on the types that happen to be passed to
> any particular call of the function.
>
> But if your code only ever calls the function with tuples of three
> floating point numbers, it can be reduced to a few assembly instructions
> to operate only on that particular type of argument. So a JIT compiled
> version is going to be a great deal smaller and faster than a statically
> compiled version could ever be.

The JIT compiler needs to find that out first. PyPy for example is good
at optimising loops, so if average() is called a million times from a
loop, each time with the same type for 'it', then that because a 'hot path'.

(Yours is not a good example however because most of the work will be
done inside sum(). If this is a built-in, then it will be executing
native code N times, not bytecode, even if it still needs to do dynamic
type-dispatch for each element.)

--
Bartc


Richard Heathfield

2/10/2016 9:51:00 PM

0

On 10/02/16 14:07, BartC wrote:
> On 10/02/2016 00:32, Öö Tiib wrote:
>> On Tuesday, 9 February 2016 16:30:19 UTC+2, Richard Heathfield wrote:
>>> On 09/02/16 14:11, anitagoyal571@gmail.com wrote:
>>> > Python is an interpreted language.
>>> > Interpreter is a program that converts the high-level program we
>>> > write into low-level program that the computer understands.
>>>
>>> That sounds more like a compiler to me.
>>
>> Good catch. AFAIK Python is simply a programming language without
>> requirement that it *must* be interpreted. There even are some
>> JIT-compiling Python 3 implementations like PyPy and Pyston.
>>
>
> PyPy is such a complex implementation that probably no one knows for
> sure exactly what it is.

That's as maybe, but the point at issue is not whether Python is an
interpreted language; the point at issue is the very definition of an
interpreter. The OP said that an "Interpreter is a program that converts
the high-level program we write into low-level program that the computer
understands", and that's /not/ an interpreter -- it's a compiler. This
is the case whether or not Python itself is interpreted, compiled, or
eaten by an okapi.

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within