O GoConqr está de visual novo! Conte para nós o que você achou.

Notas

Python Basics - 0.1

tiaan Nieuwoudt Inglês 10 páginas

Conteúdo das notas (10)

Página 1

Python/ Programming Basics

Programs make computers usable, only by performing very simple operations(Adding, subtracting, multiplication and division) .

Machine Langue is a machine's mother tongue.

Computers only respond to predetermined set of known commands.

Set of known commands is called an instruction list.

What Makes a language a language:

An Alphabet: Set of symbols used to build words of a certain language.

A Lexis aka Dictionary: Set of words the language offers.

The Syntax: Set of rules used to determine if a certain string of words make sense.

The semantics: Set of rules determining if a certain phrase makes sense.

Us as humans are not able to understand machine learning, or at least make sense out of the langue. This is why we make use of programming languages, or High-level programming languages. These languages are much like our natural languages. These languages enable humans to express commands to computers that re much more complex than those offered by IL's.

A programming written in a high level language is called Source code. Similarly, the file containing source code is called the source file.

Página 2

Compilation vs. interpretation

Computer programming is the act of composing a programming language's elements in an order that will cause the desired effect, however, such a composition must be correct in many senses:

Alphabetically - Program needs to be written in a recognizable script, such as roman, Cyrillic, etc.

Lexically - The program / script needs to respect it's lexis aka dictionary.

Syntactically - The rules of the language must be obeyed.

Semantically - The program has to make sense.

After a program has been written it has to be converted into machine language. Luckily, this can be done by the computer itself.

There are two ways of transforming a high level language into machine language, namely compilation and interpretation.

Compilation - The source program is translated onto machine language. This has to be done every time the source program is modified. the compiled version can now be used anywhere, and does not need compilation again. The program doing to compilation, is called a compiler or translator.

Interpretation - Interpretation is done every time the program runs. This program doing the interpretation is called the interpreter. Because it must be interpreted every time, the source-code alone cannot be distributed by itself. The end-user needs the relevant interpreter to run the program.

Página 3

Advantages and Disadvantages

Compilation Advantages:

The execution is usually faster.

Only the user needs the compiler - end user may use the code without it.

cause machine language is so hard to understand, your own inventions and tricks are likely to remain your secret.

Compilation Disadvantages:

The compilation itself can be very time consuming

There needs to be a compiler for every hardware platform you want the code to run on.

Interpretation Advantages:

You can run the code as soon as it's completed, no intermediate step is needed

The code is stored using the programming language. This means it can run on computers using different machine language. Compilation is not needed for every architecture.

Interpretation Disadvantages:

The interpretation will not ramp your code to high speed. The code will share the computer's power with the interpreter.

Both the user and end user need the interpreter to run the code.

Página 4

What is Python

Why was python created:

Open Source

Easily understandable

Suitable for everyday tasks

Easy to obtain

Where us python not used:

Low-level programming. Implementing an extremely effective driver or graphical engine, you won't use python.

Applications for mobile devices, although this is an ongoing growing sector of python

Página 5

Python 2 vs. Python 3

Python 2 - is of course the older brother, and it's development has intentionally been stalled. Updates on the language are still being done, but mainly focuses on fixing existing bugs and security holes. Python 2 has reached it's development deadline, but the language itself is still very much in use.

Python 3 is the newer version, and still in an ongoing development and evolving path.

These 2 version are not compatible with one another, rewriting the code is the only possible solution, however, using both languages with it's strengths and known tools are your best likely solution. Python 3 is not a better version on python 2, these two languages are different in their own ways.

Starting a new project, Python 3 is the preferred solution.

Página 6

Python and its different versions

CPython - All pythons are managed by the Python Software Foundation (PSF) This community aims to develop, improve, expand and popularize python and it's environment. The first version of python was implement is C programming language. All Python's coming from PSF is written in C language. The main reason is because the language can easily be ported and migrated to all platforms with the ability to compile and run C (which is virtually all platforms). This is why PSF implementation is often referred to as CPython.

Cython - Cython is the solution which covers one of python's most painful traits - It's lack of efficiency. Large mathematical calculations can easily be coded in Python, but the resulting code's execution time my be very time consuming. The solution to this is t write all mathematical ideas in python, and when the program is absolutely sure of the correctness and valid results, the code can easily be translated to C. This is what Cython is intended to do - to automatically translate e Python code into C code

Jython - Java Python

Version of Python written in Java, as it would be very hard using Cpython on Java based platforms. These to Programming architecture share very little common ideas. Jython can communicate with existing Java infrastructure more effectively. This implementation of Python follows Python 2 standards, there is no Jython to Python 3 thus far

PyPy and RPython - PyPy is a python environment written in a python-like language named R-python(restricted python) - a subset of Python. The source code is not run in an interpreted manner,m but rather translated to C language instead. This is useful for testing new features that may be introduced to the Python mainstream. This is why PyPy is rather a tool for Python developers rather than Python users.

Página 7

First Function

The Print() function:

The function name along with its parentheses and arguments forms the function invocation. Here are the step taking when receiving an invocation like this:

Python check if the name specified is legal.

The function's requirements are validated for the number of arguments. (e.g., if a function requires exactly two arguments and only one is given, any invocation delivering only one argument will be considered erroneous.

Python jumps into the function being invoked, also taking the arguments and passes them to the function.

The function executes it's code and causes the desired effect.

Finally, python returns to your code.

Página 8

Literals

What is a literal?

Literal is data whose values can be determined by the literal itself.

e.g. print(123) , print("123")

Integer - number without a fractional part

Floating-point(float) - Contains fractional part

The characteristic of a numeric value determines it kind, range, and application is called its type.

Página 9

Operators

An operator is a symbol in a programming language which is able to operate on values.

Arithmetic operators:

Double ** sign is an exponentiation operator. Its left is the argument base, and right the exponent.

A single * is the sign of multiplication.

The single / is the divisional operator symbol. The front value is the dividend, and the back value the divisor.

Double // is the integer divisional operator. The result lacks the fractional part, and the value is always rounded.

The % is an remainder operator.

Página 10

Variables

variables are used to store values. They consist of a name and value - any value.

There are some rules when assigning variables:

The name of the variable must be composed of upper-case, lower-case, letters, digits or the underscore(_) character.

The name must begin with a letter.

Upper- and lower case starting variables are treated different.

The name of the variable cannot be a Python keyword.

They cannot contain spaces.

Informações

Descrição
The basics of the programming language
Criado por
tiaan Nieuwoudt
Visualizações
9
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?