PCEP - Certified Entry-Level Python Programmer Study Cards

¡Supera tus tareas y exámenes ahora con Quizwiz!

Advantages to interpretation?

- you can run the code as soon as you complete it - there are no additional phases of translation; - the code is stored using programming language, not machine language - this means that it can be run on computers using different machine languages; you don't compile your code separately for each different architecture.

Disadvantages to interpretation?

-don't expect interpretation to ramp up your code to high speed - your 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.

How else can you represent the number 0.4 and 4.0 in Python?

.4 and 4. respectively. This will change neither its type nor its value.

What are the rules you must follow when giving a variable a name?

1) the name of the variable must be composed of upper-case or lower-case letters, digits, and the character _ (underscore) 2) the name of the variable must begin with a letter; 3) the underscore character is a letter; 4) upper- and lower-case letters are treated as different (a little differently than in the real world - Alice and ALICE are the same first names, but in Python they are two different variable names, and consequently, two different variables); 5) the name of the variable must not be any of Python's reserved words.

How can you represent 3 x 10^8 without writing out so many zeros?

3E8 or 3e8

What will be the result of print(2+2)?

4

What priority do these operators have <, <=, >, >=

5

What priority do these operators have ==, !=

6

What are the operators for less than, less than equal to. greater than, greater than equal to?

<, <=, >, >=

What is the assignment operator?

= (equal sign)

What is the equal equal operator?

==

What is the not equal operator?

!=

Disadvantages to compilation?

- the compilation itself may be a very time-consuming process - you may not be able to run your code immediately after making an amendment; - you have to have as many compilers as hardware platforms you want your code to be run on.

Advantages to compilation?

- the execution of the translated code is usually faster; - only the user has to have the compiler - the end-user may use the code without it; -the translated code is stored using machine language - as it is very hard to understand it, your own inventions and programming tricks are likely to remain your secret.

What is needed to create a conditional statement?

- the if keyword; -one or more white spaces; -an expression (a question or an answer) whose value will be interpreted solely in terms of True (when its value is non-zero) and False (when it is equal to zero); -a colon followed by a newline; -an indented instruction or set of instructions

True or False: Elements inside of a list must have the same type?

False: Lists may have different types of variables stored inside (ints, strings, floats, lists, etc.)

True or False: You cannot use literals to encode data and to put them into your code.

False: You CAN use literals to encode data and to put them into your code

True or False: any keyword arguments can be put before the last positional argument

False: any keyword arguments have to be put AFTER the last positional argument

True or False: a print() function invoked with more than one argument outputs them all on one line;

True

True or False: the print() function puts a space between the outputted arguments on its own initiative.

True

How do you represent the 2 Boolean values in Python?

True and False You cannot change anything - you have to take those symbols as they are, including case-sensitivity.

True or False: Are you allowed to use more than 1 keyword argument?

True. Example: Code: print("My", "name", "is", sep="_", end="*") Output: My_name_is*

True or False: Positive numbers do not need to be preceded by the plus sign.

True: Positive numbers do not need to be preceded by the plus sign, but it's permissible. The following lines describe the same number: +11111111 and 11111111.

How can you delete an element from a list?

Use the del keyword. It is an instruction: del numbers[1]

Do lists in Python support indexing?

Yes, you can refer to any position in a list by using the number.

Can you use an else statement on a loop (while, for)?

Yes.

Can you use negative indices on a list?

Yes. An element with an index equal to -1 is the last one in the list. The element with an index equal to -2 is the one before last in the list. Essentially, a negative index results in index[len(list) + i] where i is your negative index.

How is indentation achieved in Python? Can combine the indentation methods?

You can either use 4 spaces or a tab character. The indentation choice must be consistent all throughout, no mixing.

How can you represent the number eleven million one hundred and eleven thousand one hundred and eleven in Python as an integer?

You can write this number either like this: 11111111, or like that: 11_111_111.

What is an instruction list?

a complete set of known commands.

What is an interpreter?

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

A keyword argument consists of what elemests?

a keyword identifying the argument (ex. end); an equal sign (=); and a value assigned to that argument;

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 (e.g., "I am a python" is a syntactically correct phrase, while "I a python am" isn't)

Semantics

a set of rules determining if a certain phrase makes sense (e.g., "I ate a doughnut" makes sense, but "A doughnut ate me" doesn't)

Alphabet

a set of symbols used to build words of a certain language (e.g., the Latin alphabet for English, the Cyrillic alphabet for Russian, Kanji for Japanese, and so on)

What does the "continue" keyword do?

behaves as if the program has suddenly reached the end of the body

A function is able to...

cause some effect (e.g., send text to the terminal, create a file, draw an image, play a sound, etc.); this is something completely unheard of in the world of mathematics; evaluate a value (e.g., the square root of a value or the length of a given text) and return it as the function's result; this is what makes Python functions the relatives of mathematical concepts.

If the first condition of a conditional statement is not met, what keywords can you use to indicate a "Plan B"?

else, elif

When used in a string the backslash( \ ) is called an...

escape character

What does the input() function do? What kind of argument can you pass it?

input() will accept input from the user and read it into the program as a string. input() can take a string as an argument, it will print this string when waiting for input.

What does the keyword argument sep do?

instead of a space to separate the outputted arguments, the space will be replaced with the defined separator provided. Example: Code: print("Monty", "Python.", sep="-") Output: Monty-Python

Numbers handled by modern computers are of what two types?

integers, that is, those which are devoid of the fractional part; and floating-point numbers (or simply floats), that contain (or are able to contain) the fractional part.

What does the insert() method do when called on a list?

it can add a new element at any place in the list. It takes 2 arguments: list.insert(location, value)

What does a control variable do when used in a for loop?

it counts the loop's turns, and does it automatically;

How can you swap 2 variables without using a third auxiliary variable?

variable_1 = 1 variable_2 = 2 variable_1, variable_2 = variable_2, variable_1

What is the format of a while loop?

while conditional_expression: instruction

What is interpretation?

you (or any user of the code) can translate the source program each time it has to be run; the program performing this kind of transformation is called an interpreter.

What does the "pass" keyword do?

Nothing. It is simply an empty instruction.

What does the "break" keyword do?

Exits the loop it is in immediately.

Lexis

(aka a dictionary) a set of words the language offers its users (e.g., the word "computer" comes from the English language dictionary, while "cmoptrue" doesn't; the word "chat" is present both in English and French dictionaries, but their meanings are different)

What compositions must a computer program have to make sense?

A computer program must make sense: 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.

What is a literal?

A literal is data whose values are determined by the literal itself.

What is the difference between a method and a function?

A method is owned by the data it works for, while a function is owned by the whole code. result = function(arg) vs. result = data.method(arg)

Source code

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

How do we code negative numbers in Python?

As usual - by adding a minus. You can write: -11111111, or -11_111_111

How many instructions are required in an if, while or for statement?

At least 1.

Bitwise operators are __________ and can only work with arguments that are ____________.

Bitwise operators are stricter and can only work with arguments that are integers.

In an expression, parenthesis can be used to...

Change the natural order of operations and or improve readability.

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

Compilation and Interpretation

What does e stand for when representing scientific notation in Python?

E or e stand for exponent. Ex: 3E8 or 3e8 = 3 x 10^8

What are the steps in a function invocation?

First, Python checks if the name specified is legal (it browses its internal data in order to find an existing function of the name; if this search fails, Python aborts the code); second, Python checks if the function's requirements for the number of arguments allows you to invoke the function in this way (e.g., if a specific function demands exactly two arguments, any invocation delivering only one argument will be considered erroneous, and will abort the code's execution); third, Python leaves your code for a moment and jumps into the function you want to invoke; of course, it takes your argument(s) too and passes it/them to the function; fourth, the function executes its code, causes the desired effect (if any), evaluates the desired result(s) (if any) and finishes its task; finally, Python returns to your code (to the place just after the invocation) and resumes its execution.

How do you represent an octal number in Python?

If an integer number is preceded by an 0O or 0o prefix (zero-o), it will be treated as an octal value. This means that the number must contain digits taken from the [0..7] range only. 0o123 is an octal number with a (decimal) value equal to 83.

What is the hierarchy of priorities?

It determines how operators will act. Ex. multiplications precede additions

What is the replication operator and where is it used?

It is the "*" symbol. It will only operate as a replicator if 1 value is a string and the second value is a number.

What is the concatenation operator and where is it used?

It is the "+" symbol. It will only operate as a concatenator if the 2 values are strings.

What does the append() method do when called on a list?

It takes its argument's value and puts it at the end of the list which owns the method.

What kind of binding do <, <=, >, >=, == and != have?

Left side binding.

How does Python choose to represent numbers by default?

Python always chooses the more economical form of the number's presentation. Example: Code: print(0.0000000000000000000001) Output: 1e-22

Can you use a comma when representing a number in Python?

Python will not accept that, or (in very rare but possible cases) may misunderstand your intentions, as the comma itself has its own reserved meaning in Python.

What does the len() function do?

Returns the number of elements in a list.

A function name should be...

Significant

How is source code stored and what requirements must it meet?

Source code is stored in a computer file, typically a text file. The text file must be a pure text file without any decorations like different fonts, colors, embedded images or other media.

How do you represent a hexadecimal number in Python?

Such numbers should be preceded by the prefix 0x or 0X (zero-x). 0x123 is a hexadecimal number with a (decimal) value equal to 291.

What does the float() function do?

Takes 1 argument, a string, and converts it into a float.

What does the int() function do?

Takes 1 argument, a string, and converts it into an integer.

How can you print the following message without producing errors? I like "Monty Python"

The backslash can be used to escape quotes. Or Python can use an apostrophe instead of a quote. Examples: print("I like \"Monty Python\"") or print('I like "Monty Python"')

What does the binding of an operator determine? What kind of binding do most Python operators use?

The binding of the operator determines the order of computations performed by some operators with equal priority, put side by side in one expression. Most of Python's operators have left-sided binding, which means that the calculation of the expression is conducted from left to right.

What kind of binding does the exponentiation operator use?

The exponentiation operator uses right-sided binding.

Where does the name Boolean come from?

The name comes from George Boole (1815-1864), the author of the fundamental work, The Laws of Thought, which contains the definition of Boolean algebra - a part of algebra which makes use of only two distinct values: True and False, denoted as 1 and 0.

How are the shift operators depicted in Python?

The shift operators in Python are a pair of digraphs: << and >>, clearly suggesting in which direction the shift will act.

What is compilation?

The translation of source code into machine code.

What does an escape character do?

The word escape should be understood specifically - it means that the series of characters in the string escapes for the moment (a very short moment) to introduce a special inclusion.

What are the following symbols? What does each one mean and what Type of value is returned? + : - : * : / : // : % : **

These are arithmetic operators. + - addition operator. Can be used in a unary way (+4 - 10). Returns an Integer or float depending on the inputs provided (2 ints = int, 1+ floats = float). - - subtraction operator. Can be used in a unary way (-4 + 10). Returns an Integer or float depending on the inputs provided (2 ints = int, 1+ floats = float). * - multiplication operator. Returns an Integer or float depending on the inputs provided (2 ints = int, 1+ floats = float). / - divisional operator. Always returns a float. // - integer divisional operator. Always returns an integer (will round a float if a float is provided to the lesser integer). % - modulo operator. Returns the remainder of the division of 2 values provided. Returns an Integer or float depending on the inputs provided (2 ints = int, 1+ floats = float). ** - exponentiation(power) operator. Returns an Integer or float depending on the inputs provided (2 ints = int, 1+ floats = float).

What are these operators and what do they do? &, |, ~, ^

These are bitwise operators. & (ampersand) - bitwise conjunction; | (bar) - bitwise disjunction; ~ (tilde) - bitwise negation; ^ (caret) - bitwise exclusive or (xor).

Where do the functions come from?

They may come from Python itself; the print function is one of this kind; such a function is an added value received together with Python and its environment (it is built-in) they may come from one or more of Python's add-ons named modules you can write them yourself, placing as many functions as you want and need inside your program to make it simpler, clearer and more elegant.

What are scripting languages?

languages designed to be utilized in the interpretation manner.

How do you declare a list with a set length?

list_1 = [x] where x is the length of the list.

What does the n after a backslash ( \n ) in a string mean? What is the name of their combination? And what does it do?

n stands for newline and their combination is called a new line character. \n tells the console to start a new output line.

What arguments does print() expect?

print() is able to operate with virtually all types of data offered by Python. Strings, numbers, characters, logical values, objects - any of these may be successfully passed to print().

What value does the print() function return?

print() returns no value, it simply outputs data to the console.

What does the reverse() method do when called on a list?

reverse() will reverse all the values in a list.

What does the sort() method do when called on a list?

sort() will sort a list as quickly as possible.

What does the str() do?

str() accepts a number and converts it into a string.

What is the effect the print() function causes?

takes its arguments (it may accept more than one argument and may also accept less than one argument) converts them into human-readable form if needed (as you may suspect, strings don't require this action, as the string is already readable) and sends the resulting data to the output device (usually the console); in other words, anything you put into the print() function will appear on your screen.

What is the positional way?

the fact that the meaning of the argument is dictated by its position, e.g., the second argument will be outputted after the first, not the other way round

Source file

the file containing the source code

What is the meaning of keyword arguments?

the meaning of these arguments is taken not from its location (position) but from the special word (keyword) used to identify them.

What does the range() function do? What is the 3rd argument used for?

the range() function generates a sequence of integers. The range() function starts its job from 0 and finishes it one step (one integer number) before the value of its argument. A third argument will choose what to increment the list by.

The characteristic of the numeric value which determines its kind, range, and application, is called the...

type

What does the type() function do?

type() accepts any variable and returns the class of the variable.


Conjuntos de estudio relacionados

ATI Testbank Questions- OB Exam #2 part V

View Set

National FFA Food Science 2009 Test

View Set

PC Illness Women Final Exam Module 7 and Study Guide

View Set

Solutions Pre-Int 3rd Ed 3G Expressing likes and dislikes prepositions

View Set