1/136
Python Certified Entry-Level Programmer
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What type of language is python
An interpreted language
Interpreted language
Code that is translated one line/instruction at a time.
Is compilation or interpretation typically faster?
Translated compiled code tends to run faster, whereas the compilation itself takes longer.
Does the end-user need a compiler?
No
Does the end-user need an interpreter?
Yes
How is compiled code stored?
It is stored in machine language
How is interpreted code stored?
In the programming language
Where can python functions come from?
They can be built into the language, be user defined, or imported from modules
Can several things occur on the same line
NO
What happens when you dont pass arguments to print()
When you don't pass arguments to print(), it will just output a new line. You can also use the escape character \n.
How do you print a backslash in a print statement
Double it up, \
How do you print quotation marks in a print statement?
print(' " ')
What is a keyword argument
An argument unaffected by its position
What are the keyword arguments for the print statement
end, sep
Where do keyword arguments go?
After the positional argument
What is a positional argument
An argument that is dictated by its position
What is a literal
A literal is a sequence of characters used in a program to represent a constant value.
Is a char or string a literal in python?
NO
Python literals
integer, floating point. An int has no dots.
Can you use underscores in a literal?
Yes
Booleans
True 1, False 0
How to determine int or float in arithmetic?
When both arguments are integers, the result is an int. If any arguments are floats, the end result will be a float.
Integer division
An operation that divides one integer by another and yields an integer. Integer division yields only the whole number of times that the numerator is divisible by the denominator and DISCARDS ANY REMAINDER
Binding of an operator
the order of computations performed by operators with equivalent precedence
Only right binding operator
Exponentiation, **
Variable naming rules
Cannot be a keyword
Must begin with a letter
Can contain letters, digits, and underscores
Case-sensitive
Comments in python
#
How can you save input
Assign it to a variable
Can you concatenate strings
Yes, with +
Can you concatenate strings and integers
NO
How do you replicate strings
StringA * 10 or 10 * StringA
What happens if you multiply a string by a number less than or equal to0
The string will be null
String typecast
str()
Python follows PEMDAS.
True
If statement
An if keyword is followed by an expression which evaluates to a boolean. All code for this statement is indented, indicating that it falls within this statement.
Else statement
An else statement is the same thing, else followed by a colon. These statements can be nested if indentations are performed properly.
Elif statement
The elif statement is an else if, and if the first if does NOT evaluate to true, than the elif condition will be checked
How many else statements can you have for an if block
zero or one
max()
Accepts multiple arguments, returns the highest value argument
min()
accepts multiple arguments, returns least value argument
While loop
A while loop will repeat a series of statements for as long as a certain condition evaluates to true. Recall that 1 is true and 0 is false, so if arithmetic operations evaluate to either 1 or 0, that works as true or false!
While else branch
A while loop can be followed by an else branch that will execute NO MATTER WHAT
Multi-line printing
Three apostrophes
Are strings a sequence type
Yes
Can strings be sliced
Yes, they are a sequence type
for loop
The for loop opens with the "for" keyword. The variable following is the control variable of the loop. The control variable automatically counts iterations of the loop. The control variable is followed by the "in" keyword and the range() function.
range()
If passed one argument, it will start from zero and count up to, but not including, the passed argument
If passed two arguments, itll count from the first to the second
If passed three arguments, itll count from the first to the second with the increment specified by the third argument.
Does range() accept float values
No, the range() function only accepts integers.
break
Exits the loop completely, and does not resume on the next iteration
continue
exits current iteration and begins the next iteration
For else branch
The else branch will execute NO MATTER WHAT. The only case in which it wouldnt is if a break statement executed before the else was reached.
bitwise AND
argA & argB
bitwise OR
argA | argB
bitwise NOT
~argA
bitwise XOR
argA ^ argB
Can bitwise logic be passed floats?
NO. ONLY INTEGERS.
Lists
Lists are like arrays in Java, except they are mutable. Lists can store a sequence of values.
Can list store different data types
Yes
Are lists indexed?
Yes, zero-based.
List initialization
myList = [1, 2, 3]
List index of -1
An index of -1 would mean the last element, -2 the element before that, and so on.
Method
a method is owned by the data it works for while a function belongs to the whole code.
myList.append(arg)
myList.insert(index, arg)
Function
Does not belong to any data, but rather, the whole code. A function does not belong to any data, it gets data, may create new data, and typically produces a result.
Swapping values
var1, var2 = var2, var1
list.sort()
method that sorts elements in list
list.reverse()
Reverse the elements of the list, in place.
listA = listB
Creates two variables for the same list
listA = listB[:]
Copies listB values into list a
Slice [:]
Implicitly 0, -1
Used to retrieve portions of sequence data types
del myList[0:3]
Would delete the first 4 elements of myList
in/not in
will check if an element is or is not present in a data structure (or the range function)
Filling a list with a for loop
myList = [x**2 for x in range(10)]
2-D list with a for loop
A 2-D list is a list within a list. Assume EMPTY is a predefined symbol, then:
board = [[EMPTY for i in range(8)] for j in range(8)]
Function definition
def myFunction(parameters):
Where does a parameter exist
ONLY in the function
Where is a parameter defined
In the parentheses
When is a value given to a parameter
When arguments are passed to it during invocation
Parameter vs argument scope
Parameters live inside of the functions while arguments live outside of the function.
Positional arguments
Passed by the order in which they appear
Keyword arguments
Must come AFTER positional arguments, explicitly stated.
Default parameter values
def myFuncton(a = 0):
If a parameter has a default does it NEED to be initialized
No, but it still can be
How do you return
Use the return keyword, and if you follow with an argument, that value will be returned.
Can you return nothing?
Yes, it is of type None
What can be done with the None keyword
It can be assigned to variables
It can be compared to variables
It can be returned from functions
Scope
Where in the program the variable is accessible
Scope of variable in function
Only within that function
Scope of variable outside of functions
The entire program
Scope of global variables
The entire program
Function-variable interaction
Changing a parameter's value will not automatically change the argument, as an argument will pass its value and not its reference