Python Essentials 1: Module 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What 5 things make Python special? What are some drawbacks?

*** IT'S EASY TO LEARN *** >> The time needed to learn Python is shorter than for many other languages *** IT'S EASY TO TEACH *** >> the teaching workload is smaller than that needed by other languages >> this means that the teacher can put more emphasis on general (language-independent) programming techniques >> This means not wasting time on tricks, strange exceptions and incomprehensible rules. *** IT'S EASY TO USE *** >> for writing new software, it's often possible to write code faster when using Python; *** IT'S EASY TO UNDERSTAND *** >> it's also easier to understand someone else's code faster if it is written in Python *** IT'S EASY TO OBTAIN *** >> install and deploy >> Python is free, open and multiplatform.

What type of language is Python? If you want to program in Python, you'll need what interpreter?

- Python is an interpreted language. - You'll need the Python interpreter.

Fill in the blanks: You've written a code. Now, it exists as a: __________, a computer program is ACTUALLY a piece of text. So the source code is usually placed in __________.] {NOTE: It has to be pure text, without any decorations like different fonts, colors, embedded images or other media.}

- computer file - text files

Languages designed to be utilized in the interpretation manner are often called __________. The source programs encoded using them are called __________.

- scripting languages - scripts

What does the interpreter actually do?

1) First the interpreter checks if ALL subsequent lines are correct using the four aspects. > Alphabet > Lexis > Syntax > Semantics 1a) + If the compiler finds an error, it finishes its work immediately. The only result in this case is an error message that will inform you where the error is located and what caused it. 1b) + + These messages may be misleading, as the interpreter isn't able to follow your exact intentions, and may detect errors at some distance from their real causes. 1c) + + + For example, if you try to use an entity of an unknown name, it will cause an error, but the error will be discovered in the place where it tries to use the entity, NOT where the new entity's name was introduced. 2) If the line looks good, the interpreter tries to execute it (note: each line is usually executed separately, the "read-check-execute" trio can be repeated many times.) 2a) + It is also possible that a significant part of the code may be executed successfully before the interpreter finds an error. This is normal behavior in this execution model.

Who created Python?

1) It is one person's work, Guido van Rossum. - Guido van Rossum did NOT DEVELOP & EVOLVE ALL the Python components himself. - Contributions come from the continuous work of thousands (very often anonymous) programmers, testers, users, and enthusiasts. - BUT, the very FIRST idea (the seed from which Python sprouted) came to ONE head - Guido's. 2) Python was created as a "hobby" programming project. - In 1989 Guido decided to write an interpreter for the new scripting language he had been thinking about: a descendant of ABC that would appeal to Unix/C hackers. 3) In 1999, Guido defined his goals for Python: > an easy and intuitive language just as powerful as those of the major competitors; > open source, so anyone can contribute to its development; > code that is as understandable as plain English; > suitable for everyday tasks, allowing for short development times.

What are high-level programming languages?

> A language in which humans can write their programs, and a language that computers may use to execute the programs. > A language that is far more complex than machine language, and yet far simpler than natural language. > These languages enable humans to express commands to computers that are much more complex than those offered by ILs (instruction lists).

You want to know the average speed you've reached during a long journey. You know the distance, you know the time, you need the speed. Naturally, the computer will be able to compute this, but the computer is not aware of such things as distance, speed or time. Therefore, IT IS NECESSARY to instruct the computer to:

> accept a number representing the distance; > accept a number representing the travel time; > divide the former value by the latter and store the result in the memory; > display the result (representing the average speed) in a readable format. >>These four simple actions form a program<<

Compilations of computer programming must be correct in these four ways: (Mistakes in any of these four senses can cause the program to become completely useless.)

> alphabetically - a program needs to be written in a recognizable script, such as Roman, Cyrillic, etc. > lexically - each programming language has its dictionary and you need to master it; thankfully, it's much simpler and smaller than the dictionary of any natural language; > syntactically - each language has its rules and they must be obeyed; > semantically - the program has to make sense.

// Compilation vs. Interpretation \\ There are two different ways of transforming a program from a high-level programming language into machine language: Compilation and Interpretation.

>> COMPILATION: 1.] The source program is translated once by getting a file containing the machine code. 1a.] (however, this act must be repeated each time you modify the source code) 2.] Now you can distribute the file worldwide. 3.] The program that performs this translation is called a "compiler" or "translator" >> INTERPRETATION: 1.] You (or any user of the code) can translate the source program each time it has to be run. 2.] The program performing this kind of transformation is called an "interpreter". It interprets the code every time it is intended to be executed. 3.] It also means that you cannot just distribute the source code as-is, because the end-user also needs the interpreter to execute it. *** There are very few languages that can be both compiled and interpreted. ***

What do you call a tool that lets you launch your code step by step and inspect it at each moment of execution?

A debugger

What is a source code?

A program written in a high-level programming language

What makes a language? What elements does each language consist of?

Alphabet: a set of symbols used to build words of a certain language. Lexis: (aka a dictionary) a set of words the language offers its users. Syntax: a set of rules (formal or informal, written or felt intuitively) used to determine if a certain string of words forms a valid sentence. Semantics: a set of rules determining if a certain phrase makes sense.

What do you call a computer program which directly execute instructions written in a programming language?

An interpreter

Compilation vs. Interpretation Advantages and Disadvantages of Compilation // Section 1.1.1.6 \\

COMPILATION ADVANTAGES: 1. Execution of the translated code is usually faster 2. Only the user has to have the compiler. The end-user can use the code WITHOUT it. 3. The translated code is stored using machine language. COMPILATION DISADVANTAGES: 1. The compilation itself may be very time-consuming. 1a. You may not be able to run your code immediately after any amendment. 2. You HAVE TO HAVE as many -compilers- as -hardware platforms- you want your code to be run on. 2a. You want the code to run on 10 different hardware platforms? You have to have 10 different compilers.

How did Python, the programming language, get its name?

Guido van Rossum named it to honor Monty Python's Flying Circus, a BBC comedy series popular in the 1970s

Compilation vs. Interpretation Advantages and Disadvantages of Interpretation // Section 1.1.1.6 \\

INTERPRETATION ADVANTAGES: 1. You can run the code as soon as you complete it. There are no additional phases of translation. 2. Code is stored using programming language, NOT the machine one. 2a. This means that it can be run on computers using different machine languages; Code DOES NOT have to be compiled separately for different architectures. INTERPRETATION DISADVANTAGES: 1. Your code will share the computer's power with the interpreter, so it CAN NOT be really fast. 2. Both you & the end user HAVE TO HAVE the interpreter to run your code.

IDLE stands for

Integrated Development and Learning Environment.

What is IDLE?

It's an acronym that stands for Integrated Development and Learning Environment for Python

Drawbacks of Python

It's not a speed demon > Python does not deliver exceptional performance In some cases, it may be resistant to some simpler testing techniques > This may mean that debugging Python's code can be more difficult than with other languages > Fortunately, making mistakes is always harder in Python.

Where can we see Python in action? Where is it RARELY seen?

It's used extensively to implement complex "Internet services" like: search engines, cloud storage and tools, social media and so on. Many developing tools everyday use applications scientists IT project testers RARE: + low-level programming: (sometimes called "close to metal" programming): if you want to implement an extremely effective driver or graphical engine, you wouldn't use Python + applications for mobile devices: although this territory is still waiting to be conquered by Python, it will most likely happen someday.

Programs must be translated into:

Language

Who are Python's rivals? Python has two direct competitors, with comparable properties and predispositions. Python itself lies somewhere between these two creations.

Perl > A scripting language originally authored by Larry Wall > Perl is more traditional & conservative than Python > Perl resembles some of the good old languages derived from the classic C programming language. Ruby > A scripting language originally authored by Yukihiro Matsumoto. > Ruby is more innovative & full of fresh ideas

Types of Python + Python 2 + Python 3 + Cython + Jython + CPython + PyPy and RPython

Python 2 and Python 3 THEY ARE NOT COMPATIBLE WITH EACH OTHER Python 2: + Older + It IS updated, but NO significant language changes are made. + They fix freshly discovered bugs & security holes Python 3 + The newer & current version + Still evolving and creating it's own standards & habits + Although similar to Python 2, Python 3 is a completely different language Cython + Cython is used to automatically translate the Python code into "C" code. + Cython is one of a possible number of solutions to the most painful of Python's trait - the lack of efficiency. + Large & complex mathematical calculations may be easily coded in Python, but the resulting code's execution may be extremely time-consuming. + Translating Python into "C" will run faster than just pure Python Jython + "J" is for "Java" + Follows Python 2 standards + This is useful if you develop large & complex systems written entirely in Java and want to add some Python flexibility to them. + The traditional CPython may be difficult to integrate into such an environment, as C and Java live in completely different worlds and don't share many common ideas. CPython + All Pythons coming from the PSF are written in the "C" language. + This is why the PSF implementation is often referred to as CPython. PyPy and RPython + PyPy (a Python within a Python) + RPython (Restricted Python) + "PyPy" represents a Python environment written in RPython + RPython is a "Python-like language" + PyPy is rather a tool for people developing Python than for the rest of the users. + PyPy is compatible with the Python 3 language.

What Python version is covered in this course?

Python 3

What is Python? What are some characteristics?

Python is a high-level programming language with dynamic semantics. Python is: - widely-used - interpreted - object-oriented - used for general-purpose programming - "dynamic semantics" means "growth of information in time" - - "dynamic means "constant change or motion" - - "semantics" means "the meaning of a word, phrase, sentence, or text"

The PSF (Python Software Foundation)

The PSF (Python Software Foundation) + manages Pythons that are called "canonical" & "reference Pythons". + Any other implementation of the language should follow all standards established by the PSF. + All Pythons coming from the PSF are written in the "C" language. + This is why the PSF implementation is often referred to as CPython.

What is CPython?

The default implementation of the Python programming language

The interpreter reads the source code in what directions?

Top to bottom & from left to right. (Just like you read a piece of paper, or a book. There are SOME exceptions not covered in this study set)

You've successfully written a program. How do we persuade the computer to execute it?

You have to render your program into machine language. (Luckily, the translation can be done by a computer itself, making the whole process fast and efficient.)

Python is an example of:

a high-level programming language

A complete set of known commands is called:

an instruction list

Computer programming is the act of:

composing the selected programming language's elements in the order that will cause the desired effect.

A language is a means (and a tool) for:

expressing and recording thoughts.

A complete set of known commands is called an: __________ > It is also the alphabet of a machine language

instruction list (or it is abbreviated to IL)

Computers have their own language, too, called __________, which is very rudimentary. ***** (Rudimentary means "involving or limited to basic principles") *****

machine language

New words are created every day and old words disappear. These languages are called:

natural languages

Which one of the following is an example of a Python extension file?

py

A program written in a high-level programming language is called a:

source code

the file containing the source code is called the:

source file.


Set pelajaran terkait

ACM and Software Engineering Codes of Ethics

View Set

Ch. 14 15 & 16 Test- Microbiology

View Set

Nursing Assessment: Hematologic Function

View Set

Economics - Elasticity Chapter 6

View Set

AP Macroeconomics Unit 2 Progress Check: MCQ

View Set

crisis 2 exam four chapter questions

View Set