PCAP: Programming Essentials in Python

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

output? for i in range(6,1,-2)

6,4,2

positional parameter passing

A technique which assigns the ith (first, second, and so on) argument to the ith (first, second, and so on) function parameter

series of if statements - when is the last else executed?

Each if is tested separately. The else is executed if the last if is False.

output? i = 111 for i in range(2, 1): print(i) else: print("else:", i)

Else: 111

'beta' > 'Beta'?

True (upper-case letters are taken as lesser than lower-case)

UTF

Unicode Transformation Format

variable

a named location reserved to store values in the memory. A variable is created or initialized automatically when you assign a value to it for the first time (length = 5)

Namespace

a space in which some names exist and the names don't conflict with each other (i.e., there are not two different objects of the same name).

code page

a standard for using the upper 128 code points to store specific national characters (to determine the meaning of a specific code point, you have to know the target code page)

what value is returned by the input ()?

a string

find() two-parameter variant

allows you specify the index at which the search will be started

literal

data whose values are determined by the literal itself and are used to encode data and put them into your code (123 is literally one hundred and twenty-three while C can = anything, so 123 is literal but C is not)

newline

empty line of code

Syntax of an empty dictionary

empty_dictionary = { }

break

exits the loop immediately, and unconditionally ends the loop's operation; the program begins to execute the nearest instruction after the loop's body; keyword

What is the scope of a variable outside of a function?

inside the function body unless the function defines the variable of the same name

unary operator

is an operator with only one operand (-1 or +3)

Return with an expression

it causes the immediate termination of the function's execution. the function will evaluate the expression's value and will return it as the function's result.

Syntax for accessing a dictionary item

item1 = newDict["key"] or item2 = newDict.get("key")

for j in myList

j is the control variable of the loop, where the in keyword introduces a syntax element describing the range of possible values being assigned to j

example of find() with 2 parameters

kappa.find('a', 2)

What are dictionaries comprised of?

key-value pairs

Assert

keyword instruction that evaluates an expression

Global

keyword that extends a variable's scope in a way which includes the functions' bodies

return

keyword to tell a function to return some value; this statement also exits the function

python_implementation()

returns a string denoting the Python implementation (expect CPython here, unless you decide to use any non-canonical Python branch)

processor()

returns a string filled with the real processor name (if possible)

python_version_tuple()

returns a three-element tuple filled with the major and minor part of Python's version and the patch level number

len() with a string

returns number of characters

system()

returns the generic OS name as a string.

Machine()

returns the generic name of the processor which runs your OS together with python and your code

hypot(x, y)

returns the length of the hypotenuse of a right-angle triangle with the leg lengths equal to x and y

factorial(x)

returns x! (x has to be an integral and not a negative)

round ()

rounds the outputted result to the number of decimal places specified in the parenthesis, and return a float round(miles_to_kilometers,1)

seed()

sets the seed with the current time

Sin(x)

sine of x

compilation

source program is translated once (must be repeated each time you modify the source code) by getting a file containing the machine code; now you can distribute the file worldwide. The program that performs this translation is called a compiler or translator

scripts

source programs encoded using scripting languages

Classify these literals ("1.5", 2.0, 528, False)

string, numerical literal float, numerical literal int, boolean literal

editor

supports you in writing code

exponentiation of square root

x ** 0.5

can you treat strings as lists?

yes, you can index and slice them

interpretation disadvantages

-Code will share the computer's power with the interpreter, so it can't be really fast -Both you and the end user have to have the interpreter to run your code

examples of bitwise operators

&, |, ^, ~

How do you replicate a string?

* (commutative)

replicator operator

*, It replicates the string the same number of times specified by the number For example "James" * 3 times "JamesJamesJames"

a one bit shift to the left/right

*2, /2

a two, three, four bit shift to the left/right

*4,*8,*16 /4, /8, /16

How do you concatenate a string?

+ (not commutative)

concatenation operator

+, string + string, glues two strings into one

What does the find() method generate if the substring is non existent?

-1

compilation disadvantages

-Compilation itself maybe be very time consuming; you might not be able to run code immediately after any change -You have to have as many compilers as hardware platforms you want your code to be run on

interpretation advantages

-You can run the code as soon as you complete it; no additional phases of translation -Code is stored using programming language, not the machine one, which means it can be run on computers using different machine languages -You dont compile your code separately for each different architecture

logical vs. bitwise operators

-logical operators do not penetrate into the bit level of its argument; they're only interested in the final integer value -Bitwise operators are stricter: they deal with every bit separately

//

// is integer divisional operator also known as floor division; results are always rounded to the lesser integer

what index does an item stored at the beginning of a list have?

0

output? for i in range(5): print(i) else: print("else:", i)

0 1 2 3 4 Else: 4

two rules for functions

1. You mustn't invoke a function which is not known at the moment of invocation. 2. You mustn't have a function and a variable of the same name

How many characters does ASCII provide for and how many are we interested in?

256, 128

how many times will this code run counter = 5 while counter != 0 print("blah") counter -= 1

5 times

how many built-in exceptions are there in Python 3?

63, in a tree-shaped hierarchy (more abstract at the top of the tree and more concrete at its leaves)

shift operators

<< and >>; The left argument of these operators is an integer value whose bits are shifted. The right argument determines the size of the shift. (Not commutative)

interpreter

A computer program that directly executes instructions written in a programming language

function vs. method

A method is owned by the data it works for, while a function is owned by the whole code.

input ()

Able to read data enter by the user and to return the same data to the running program; program then can manipulate the data, making the code truly interactive

float ()

Float () function takes one argument (eg a string: float (string)) and tries to convert it into a float

What is the word internationalization commonly shortened to?

I18N

if-elif-else statement -when is each executed?

If the condition for if is False, the program checks the conditions of the subsequent elif blocks - the first elif block that is True is executed. If all the conditions are False, the else block will be executed

Integers (or simply ints)

Integers (or simply ints) are one of the numerical types supported by Python. They are numbers written without a fractional component, e.g., 256, or -1 (negative integers).

IDLE

Integrated Development and Learning Environment

platform module

Lets you access the underlying platform's data, ie the hardware, operating system, and interpreter version information

append() method with a string

NOT POSSIBLE

insert() method with a string

NOT POSSIBLE

Version()

OS version as a string

in what python version have dictionaries become ordered by default?

Python 3.6x

using / at the end of a line

Python will continue the line of code in the next line of code (improves readability)

What forms the python standard library?

Python's models and built-in functions

Message that occurs when a function has no termination condition (base case)

RecursionError maximum recursion depth exceeded

A typical method invocation

Result = data.method(arg); Name of the method is preceded by the name of the data which owns the method; Then, add a dot; Followed by method name; And () enclosing the arguments

A typical function invocation

Result = function(arg); The function takes an argument, does something, and returns a result

dir()

Returns an alphabetically sorted list containing all entities' names available in the module identified by a name passed to the function as an argument

pseudocode

Shorthand notation for programming which uses a combination of informal programming structures and verbal descriptions of code.

What is the most common character and its code point in ASCII?

Space, 32

elem in mylist/elem not in mylist

The first of them (in) checks if a given element (its left argument) is currently stored somewhere inside the list (the right argument) - the operator returns True in this case; The second (not in) checks if a given element (its left argument) is absent in a list - the operator returns True in this case.

print () vs input ()

The print() function sends data to the console, while the input() function gets data from the console

'alpha' < 'alphabet'?

True (longer string is considered greater)

integer vs. float rule

When both arguments are integers, the result is an int; when at least one is a float, the result is a float too

myList = [1, 2, 3, 4, 5].....del myList[0:2] - output?

[3, 4, 5]

escape character

\ (backslash); signifies that the character after the \ has a different meaning

newline character

\n

function

a block of code that performs a specific task when the function is called (invoked)

print ()

a built-in function that prints/outputs a specified message to the screen/consolewindow

what is necessary to differentiate a tuple from a single value when writing its code?

a comma

Instruction List (IL)

a complete set of known commands; the alphabet of the machine language (they vary by size and what they contain)

disjunction

a compound that requires at least one condition to be met

AssertionError

a concrete exception raised by the assert instruction when its argument evaluates to False, None, 0, or an empty string

ImportError

a concrete exception raised when an import operation fails

MemoryError

a concrete exception raised when an operation cannot be completed due to a lack of free memory

OverflowError

a concrete exception raised when an operation produces a number too big to be successfully stored

KeyboardInterrupt

a concrete exception raised when the user uses a keyboard shortcut designed to terminate a program's execution

KeyError

a concrete exception raised when you try to access a collection's non-existent element (e.g., a dictionary's element)

IndexError

a concrete exception raised when you try to access a non-existent sequence's element (e.g., a list's element)

conjunction

a connection that requires the simultaneous fulfillment of two conditions

e

a constant with a value that is an approximation of Euler's number (e)

pi

a constant with a value that is an approximation of π

radians(x)

a function that converts x from degrees to radians

sorted()

a function that sorts a dictionary

What kind of language is Python?

a high-level programming language (not a machine language or a natural language)

import

a keyword instruction that allows you to import modules into a Python script

raise

a keyword instruction that enables you to simulate raising actual exceptions

try

a keyword that begins a block of code which may or may not be performing correctly

except

a keyword that starts a piece of code to be executed if anything in the try block goes wrong

List comprehension

a list that is created on-the-fly during program execution, and is not described statically; row = [WHITE_PAWN for i in range(8)]

and

a logical conjunction (binary) operator where if both operands are true, the condition is true; priority that is lower than the one expressed by the comparison operators

Keys()

a method possessed by each dictionary that returns an iterable object consisting of all the keys gathered within the dictionary

Get()

a method that allows you retrieve an item from a dictionary

copy()

a method that allows you to copy a dictionary

update()

a method that allows you to insert an item into a dictionary

clear()

a method that allows you to remove all of a dictionary's items

startswith()

a method that checks if a given strings starts with a specified substring

capitalize()

a method that creates a new string filled with characters taken from the source string, but changes the fist character of the string to a capital letter while other letters are changed to lowercase

values()

a method that is similar to keys() but returns values

center()

a method that makes a copy of the original string, trying to center it inside a field of a specified width;

upper()

a method that makes a copy of the source string, replaces all lower-case letters with their upper-case counterparts, and returns a string as the result

strip()

a method that makes a new string lacking all leading and trailing whitespaces

Reverse()

a method that reverses a list

sort()

a method that sorts lists as fast as possible

split()

a method that splits the string and builds a list of all detected substrings; assumes that substrings a re delimited by whitespace

Insert()

a method that takes its argument's value and puts it at any place in the list

Append()

a method that takes its argument's value and puts it at the end of the list which owns the method, increasing the list's length by 1

Code point

a number which makes a character (32 is the code point that makes a space in ASCII encoding)

isalpha()

a parameterless method that checks if the string contains alphabetical characters and returns True or False

islower()

a parameterless method that checks if the string contains only LOWWERCASE alphabetical characters and returns True or False

isupper()

a parameterless method that checks if the string contains only UPPERCASE alphabetical characters and returns True or False

isspace()

a parameterless method that checks if the string contains only WHITESPACES and returns True or False

isdigit()

a parameterless method that checks if the string contains only digits and returns True or False

isalnum()

a parameterless method that checks if the string contains only digits or alphabetical characters and returns True or False

lower()

a parameterless method that makes a copy of the source string, replaces all upper-case letters with lower-case, and returns a new string as the result

deaf program

a program which doesn't get a user's input

source code

a program written in a high-level programming language (in contrast to the machine code executed by computers)

comment

a remark inserted into the program, which is omitted at runtime (begins with a #)

function

a separate part of the computer code that is able to: (some functions do both) -Cause some effect (send txt to the terminal, create a file, draw an image, play a sound) -Evaluate a value or some values (the square root of a value)That is, a function may have an effect or a result

endless (infinite) loop

a sequence of instructions in a program which repeat indefinitely

bit mask

a sequence of zeros and ones, whose task is to grab the value or to change the selected bits

syntax

a set of rules (formal or informal) used to determine if a certain string of words forms a valid sentence

semantics

a set of rules determine if a certain phrase makes sense (I ate a donut vs a donut ate me)

Method

a specific kind of function that is able to change the state of the selected entity; can change the internal state of the data from which it has been invoked

Recursion

a technique where a function invokes itself; these calls consume a lot of memory

replace()

a two-parameter method that returns a copy of the original string in which all occurrences of the first argument have been replaced by the second argument; adding a third argument limits the number of replacements

str ()

a type conversion; converts a number into a string

list

a type of data in Python used to store multiple objects. It is an ordered and mutable collection of comma-separated items between square brackets

Sequence

a type of data in Python which is able to store more than one value (or less than one, as a sequence may be empty), and these values can be sequentially browsed, element by element. (Ex: the list)

Commutative operations

a × b = b × a (doesn't matter the order you put the variables in)

degrees(x)

acting in the other direction (from radians to degrees)

Syntactic candy (or sugar):

additions to code which dont improve the language's expressive power, but simplify the developer's work

lexis

aka a dictionary or a set of words the language offers its users

The one rule for mixing positional and keyword arguments

all positional arguments must be placed BEFORE keyword arguments

center() two parameter variant

allows you to surround the string with something other than spaces

ArithmeticError

an abstract exception including all exceptions caused by arithmetic operations like zero division or an argument's invalid domain

LookupError

an abstract exception including all exceptions caused by errors resulting from invalid references to different collections (lists, dictionaries, tuples, etc.)

Slice

an element of Python syntax that allows you to make a brand new copy of a list or parts of a list

loop's body

an instruction or set of instructions executed inside the while loop; should aim to change the condition's value or else it could run indefinitely

del

an instruction, not a function, that removes elements from a list, thus decreasing the list length

what are the three logical operators?

and, or, not

else clauses with while and for loops

are always executed after the loop finishes its execution, as long as the loop has not been terminated by a 'break'

Tuples

are ordered and immutable collections of data, like lists. They are created using parenthesis or values separated by commas and they contain elements that may be different types

Boolean values

are the two constant objects True and False used to represent truth values (in numeric contexts 1 is True, while 0 is False.

Dictionaries

are unordered*, mutable, and indexed collections of data

Unicode

assigns unique (unambiguous) characters (letters, hyphens, ideograms, etc.) to more than a million code points (The first 128 Unicode code points are identical to ASCII, and the first 256 Unicode code points are identical to the ISO/IEC 8859-1 code page (a code page designed for western European languages).

continue

behaves as if the program has suddenly reached the end of the body; the next turn is started and the condition expression is tested immediately; keyword

&

bitwise conjunction operator; requires two 1's to provide 1 as the result; "and"

|

bitwise disjunction operator; requires at least one 1 to provide 1 as the result; "or"

^

bitwise exclusive or (xor); requires exactly one 1 to provide 1 as the result

max ()

built in function that finds the max of the variables in the parenthesis

min ()

built in function that finds the min of the variables in the parenthesis

pow(x, y)

built-in function that finds the value of xy (mind the domains)

4 basic types of functions in Python

built-in functions, pre-installed modules, user-defined functions, and the lambda functions

How are modules identified?

by their names

Mutable data

can be freely updated at any time; "in situ"; ex: the list

del instruction with a string

can eliminate the entire string but not a part of it

Immutable data

cannot be modified at any time

In and not in operators with strings

check if the left argument (a string) is or is not in the right argument (another string) (returns True or False)

Choice(sequence)

chooses a pseudo random element from the input sequence and returns it

bubble sort

compares adjacent elements, using swapping to achieve a goal

<, <=, >, >=

comparison or relational operators (they compare values)

two different ways of transforming a program from a high-level programming language into machine language

compilation and interpretation

what operations are performed on strings?

concatenation (joining) and replication

source file

contains source code

str()

converts a number into a string

[ : ]

copies a list's entire contents, not the list's name

Cos(x)

cosine fo x

count() method with a string

counts all occurrences of the element inside the sequence

Syntax of defining a function

def functionName(optional parameters): functionBody

syntax for using the del instruction with a dictionary

del dictionary[key]

del numbers[1]

delete the element that is numbered 1 in a list called numbers

random module

delivers some mechanisms allowing you to operate with pseudorandom numbers

Mutability

describes a data's readiness to be freely changed during program execution

type ()

determines the kind, range, and application of the numeric value

binding

determines the order of computations performed by some operators with equal priority, put side by side in one expression; most are left-sided binding (not exponentiation)

Syntax of a dictionary

dictionary = { "key" : "value", "key2" : "value2"}

syntax for update()

dictionary.update({"duck" : "canard"})

syntax for adding a new key to a dictionary

dictionary['newly'] = 'new value'

syntax for adding a new key to a dictionary

dictionary[new key] = new value

/

division; the value in front of hte slash is a dividend and the value behind the slash is a divisor; Always produces a float

rstrip()

does nearly the same as the lstrip() method but affects the opposite side of the string

rfind()

does the same thing as find() method but starts its search from the end of the string

Syntax of an empty tuple

emptyTuple = ()

keyword arguments

end= sep= (choose what you separate everything by)

What do modules consist of?

entities (can be functions, variables, constants, classes, and objects)

nesting

every else refers to the if which lies at the same indentation level

for loop

executes a set of statements many times

while loop

executes a statement or a set of statements as long as a specified boolean condition is true

parameters

exist only inside functions in which they have been defined, and the only place where the parameter can be defined is a space between a pair of parentheses in the def statement

arguments

exist outside of functions; they are carriers of values passed to corresponding parameters

exp(x)

finding the value of ex;

syntax to find the total sum of the elements in a list

for k in range(len(myList)..... total+=myList[k]

syntax for sorted()

for key in sorted(dictionary.keys()):

Syntax to use items() method to loop through a dictionary's keys and values

for key, value in polEngDict.items(): print("Pol/Eng ->", key, ":", value)

bitwise operators

four operators that allow you to manipulate single bits of data; arguments must be integers

syntax of a selective import

from + module name + import + name or list of names of entity/entities

syntax of importing all entities from an indicated module

from module import *

range()

generates a sequence of numbers. It accepts integers and returns range objects. starts from 0 and ends one value before the value of its argument

numbers[-1]

goes to the last position in the last

>

greater than operator

>=

greater than or equal to operator. the non-strict variant of >

package

groups modules together

if versus while statements

if performs statements only once; the while statement is repeated as long as the condition evaluates to True

Syntax of of importing a module

import + name of module, name of next module, etc.; invoked before the use of any of the module's entities

Syntax of dir()

import module / dir(module)

Syntax of aliasing

import module as alias OR from module import name as alias

What is the scope of a variable that exists inside a function?

inside the function body

what value must not be iterated through by the for loop?

integer

octal value prefix

integer preceded by an 0o; must contain digits taken from 0....8 range only

two types of numbers

integers and floats

Syntax for get()

item2 = newDict.get("key")

natural languages

languages where new words are created every day and old words disappear

<=

less than or equal to operator. the non-strict variant of <

Syntax of append ()

list.append(value)

Syntax of insert ()

list.insert(location, value)

not

logical construction operator (unary) where returns false if the result is true, and returns true if the result is false; priority is as high as unary +-

or

logical disjunction operator (binary) where if any of the operands are true, the condition is true; lower priority than and

max() with a string

looks at the ASCII code to find a maximum

min() with a string

looks at the ASCII code to find a minimum

computer's language?

machine language

positional arguments

meaning of the argument is dictated by tis position (the second argument comes after the first and so on)

popitem()

method that allows you to remove the last item from a dictionary

title()

method that changes every word's first letter to upper-case and turns all other characters of that word to lower case

endswith()

method that checks if the given string ends with the specified argument and returns True or False depending on the result

find()

method that is similar to index() - it looks for a substring and returns the index of the first occurrence of the substring

swapcase()

method that makes a new string by swapping the case of all letters within the source string; all other characters remain untouched

lstrip()

method that returns a newly created string formed from the original one by removing all leading whitespaces; with an argument, it removes all leading characters in the argument, not just white spaces

Syntax of qualifying names

module.name (module indicates the namespace in which the name exists)

How do you divide a piece of software into separate but cooperating parts?

modules

%

modulo where the result is the remainder left after the integer division

Syntax to create an empty list

myList = []

if an except branch is executed, are the other branches visited?

no

another way to write number % 2 == 1

number % 2:

TypeError

occurs when you assign a function arguments when it doesn't take any ... def hi():.... Then try, hi(5)

NameError

occurs when you try to invoke a function before you define it

Syntax of a one-element tuple

oneElementTuple = (1, ) or oneElementTuple2 = 1.,

shifting

only applied to integer values and single bits

Indexing

operation of selecting an element from the list

+

operator that allows you to add numbers

shadowing

parameter x shadows any variable of the same name but only inside the function defining the parameter

loop

performing a certain part of the code more than once

how do you pass arguments to a function?

positional argument passing, keyword argument passing, or a mix of both

syntax for getting a dictionary value

print(dictionary['value'])

Random()

produces a float number x coming from the range (0.0, 1.0)

How should you order exception branches?

put more concrete exceptions before general exceptions

What are the integer random value functions?

randrange (right sided exclusion, can have 3 arguments), randint(left, right+1) (no right sided exclusion)

Syntax of the range function

range(start, stop, step) where start specifies the start of the sequence (0 by default), stop specifies the end of the sequence (it is not included), and step specifies the increment (1 by default)

index() method with a string

searches the sequence from the beginning, in order to find the first element of the value specified in its argument

alphabet

set of symbols used to build words of a certain language

seed(int_value)

sets the seed with the integer value int_value

What does ASCII stand for?

short for American Standard Code for Information Interchange

compound assignment operators

shortcut operators that modify values assigned to variables j=j+2*k ...j +=2*k

What is hypot(x, y) the same as?

sqrt(pow(x, 2) + pow(y, 2)) but more precise

[start : end]

start is the * start is the index of the first element included in the slice; end is the index of the first element not included in the slice

Which method combines the effects caused by rstrip() and lstrip()?

strip() method

chr()

takes a code point and returns its character

ord()

takes a single character and returns its ASCII/UNICODE code point (its argument is 1 character)

list() function with a string

takes its argument (the string) and create a new list containing all the string's characters, one per list element

join()

takes one argument that is a list with only string elements; the list's elements will be joined into one string with each element being separated by the invoked string

len()

takes the list's name as an argument and returns the number of elements currently stored inside the list

Tan(x)

tangent of x

counter variable

tells how many times to run a loop

Python aka CPython

the PSF implementation and the most influential Python among all the Pythons in the world; the default implementation of the python programming language

acos(x)

the arccosine of x

asin(x)

the arcsine of x

atan(x)

the arctangent of x

log2(x)

the binary logarithm of x (more precise than log(x, 2))

ceil(x)

the ceiling of x (the smallest integer greater than or equal to x)

log10(x)

the decimal logarithm of x (more precise than log(x, 10))

==

the equal to operator, which compares the values of two operands. If they are equal, the result is True. (it is binary; needs two arguments; left-sided binding).

what happens if none of the specified except branches matches the raised exception?

the exception remains unhandled

what happens if something goes wrong in the try and except blocks?

the execution immediately jumps out of the block and into the first instruction located after the except keyword (might omit some instructions in the block)

floor(x)

the floor of x (the largest integer less than or equal to x)

acosh(x)

the hyperbolic arccosine;

asinh(x)

the hyperbolic arcsine;

atanh(x)

the hyperbolic arctangent.

cosh(x)

the hyperbolic cosine;

sinh(x)

the hyperbolic sine;

tanh(x)

the hyperbolic tangent;

what does the else statement apply to?

the if statement directly in-line and above it

Return without an expression

the immediate termination of the function's execution, and an instant return to the point of invocation

What does the index() method with a string return?

the index of the first occurrence of the argument or a ValueError exception if the element is not there

<

the less than operator

log(x, b)

the logarithm of x to base b

keyword argument passing

the meaning of the argument is dictated by its name, not its position

BaseException

the most general (abstract) of all Python exceptions - all other exceptions are included in this one (except: and except BaseExecption: are the same)

ASCII

the most widely used standard implemented by (almost) all computers and operating systems all over the world to create character-number assignments

log(x)

the natural logarithm of x

!=

the not equal to operator, which compares the values of two operands. If they are not equal, the result is True. (it is binary; needs two arguments; left-sided binding).

Scope of a name

the part of a code where the name is properly recognizable

the logic

the part processing data and producing results

the user interface

the part that communicates with the user using widgets and a graphical screen

how many arguments do you need per function parameter?

the same amount

What method is the reverse of the join() method?

the split() method

Which method is the reverse of the endswith() method?

the startswith() method

Index

the value inside the brackets which selects an element of the list by its position; can be any expression

trunc(x)

the value of x truncated to an integer (be careful - it's not an equivalent either of ceil or floor)

cascade

the way to assemble subsequent if-elif-else statements -else can only exist if there is an if -else is the last branch of the cascade -else is optional

value

the word you get from the dictionary

key

the word you look for in a dictionary

most important difference between an int and float

they are stored differently in the computer's memory

find() three-parameter variant

third argument points to the first index which wont be taken into consideration during the search

debugger

tool able to launch your code step by step and allowing you to inspect it at each moment of execution

Error Codes

traceback, location of the error (Python shows the place where it first notices the effects of the error, not necessarily the error itself), content of the erroneous line, name of the error

syntax of multiline strings

tripled quotes or apostrophes around the string

pairwise equivalent

two ways of writing the same conditions

Matrix

two-dimensional array; board = [[EMPTY for i in range(8)] for j in range(8)]

Swapping values in Python

use commas to delineate variables to be switched Variable1 = 1 /Variable2 = 2 /Variable1, Variable2 = Variable2, Variable1

how to find an element of a matrix

use coordinates, a vertical one (row number), a horizontal one (column number)

logical operators

used to build conjunctions and disjunctions; they take their arguments as a whole regardless of how many bits they contain

conditional statement

used to execute some code only if a certain condition is met

console

used to launch your newly written code and stop it forcibly when it gets out of control

UTF-8

uses as many bits for each of the code points as it really needs to represent them (one of the most commonly used UTFs)

Aliasing

using the as keyword to import a module as whatever name you want

Overloading

using the same operator against different types of data (an operator is overloaded with different duties)

Scalar

variable that stores exactly one given value at a time

Multi-value

variables that can hold more than one value at a time

Raising an exception

when Python has no idea what to do with your code

decomposition

when a coder divides the code into well isolated pieces, encoding each of them in the form of a separate function

aliased

when set to True (or any non-zero value) it may cause the function to present the alternative underlying layer names instead of the common ones;

terse

when set to True (or any non-zero value) it may convince the function to present a briefer form of the result (if possible)

When are two strings equal?

when they consist of the same characters in the same order

When are you a module's supplier?

when you create a brand new module

When are you a module's user?

when you use an already existing module, written by someone else, or create by yourself

binary system

is a system of numbers that employs 2 as the base. Therefore, a binary number is made up of 0s and 1s only, e.g., 1010 is 10 in decimal.

binary operator

is an operator with two operands (4+5 or 12%5)

**

is exponentiation; left argument is the base, the right is the exponent, 2^3 is 2**3; uses right sided binding

Scripting languages

languages designed to be utilized in the interpretation manner/ they create scripts

keyword arguments

meaning of arguments is taken not from location (position) but from the special word (keyword) used to identify them; has to be after the last positional argument; consist of 3 elements - 1. the keyword identifying hte argument 2. an = sign 3. a value assigned to that argument

language

means/tool for expressing and recoding thoughts

int ()

takes one argument (eg a string, int(string)) and tries to convert it to an integer; if it fails, the whole program will fail too

operator

Operators are special symbols or keywords which are able to operate on the values and perform (mathematical) operations, e.g., the *operator multiplies two values: x * y.

PSF

Python Software foundation; Pythons maintained by the PSF are canonical and are reference pythons

what are the two types of loops?

while and for

another way to write while number != 0

while number:

ZeroDivisionError

when you try to divide by 0

hexadecimal value prefix

0x (16 as its base)

~

bitwise negation

Array

list in a list

4 aspects of a language

alphabet, lexis, syntax, semantics

components of functions

an effect, a result, an argument within ()

compilation advantages

-Execution of the translated code is usually faster -Only the user has to have the compiler, end user may use code without it -Translated code is stored using machine language - because machine language is hard to understand, this makes your own inventions/programming tricks likely to remain secret

priority table

1. +, - (unary) 2. ** 3. *, /,//, % 4. +, - (binary) 5. <,<=,>, >= 6. ==, !=

assignment operator

= (assigns the value of the right argument to the left)

expression

An expression is a combination of values (or variables, operators, calls to functions) which evaluates to a value, e.g., 1 + 2. simplest expression is a literal itself

Floating-point numbers (or simply floats)

Floating-point numbers (or simply floats) are another one of the numerical types supported by Python. They are numbers that contain (or are able to contain) a fractional component, e.g., 1.27.

elif statement

a conditional statement that: -checks more than just one condition -stops when the first statement which is true is found; "otherwise"

if-then statement

a conditional statement that: -has the if keyword -one or more white spaces -an expression whose value will be interpreted solely in terms of True (value is non zero) and false (value equal to zero) -a colon followed by a newline - an indented instruction (or more instructions). if true_or_not: do_this_if_true

if-else statement

a conditional statement where -else says what to do if the condition specified for the if is not met

interpretation

a user can translate the source program each time it has to be run; the program performing this kind of transformation is called an interpreter, as it interprets the code every time it is intended to be executed

identifier

a variable's unique name; A legal identifier name must be a non-empty sequence of characters, must begin with the underscore(_), or a letter, and it cannot be a Python keyword. The first character may be followed by underscores, letters, and digits. Identifiers in Python are case-sensitive.

hierarchy of priorities

unary + and - have the highest priority then: **, then: *, /, and % lowest priority: binary + and -.


Ensembles d'études connexes

Chapter 14: Assessing Skin, Hair, and Nails

View Set

Exam 8 Adult Health Chapter 49, 50, 51

View Set

CH#4: Life Insurance Policy Provisions, Options and Riders Q&A

View Set

5th grade SS - Industrial Revolution Leads to Massive Immigration

View Set

Introduction to Computer Networks and Data Communications

View Set

ANS 100 Midterm 2 REVIEW, ANS 100 Study Guide for Midterm #2 final!

View Set