4th Quarter Computer Literacy
How do you insert COMMENTS in Python code?
# This is a comment
What is the correct file extension for Python files?
.py
Which operator can be used to compare two values?
==
and
A logical operator
not
A logical operator
or
A logical operator
pass
A null statement, a statement that will do nothing
Rules for writing identifiers 2
An identifier cannot start with a digit.
A variable that can only have two values, True or False.
Boolean
False
Boolean value, result of comparison operations
True
Boolean value, result of comparison operations
Python's advantage 1
Developers can learn it quickly
bool('False')
False
assert
For debugging
Python's advantage 5
Huge amount of additional open-source libraries
Rules for writing identifiers 1
Identifiers can be a combination of letters in lowercase or uppercase or digits or an underscore.
Rules for writing identifiers 3
Keywords cannot be used as identifiers.
Legal Variable Names
Myvar, myvar, My_var, myVar1
None
Represents a null value
max(list)
Returns item from the list with max value
min(list)
Returns item from the list with min value
Rules for writing identifiers 5
Spaces are not allowed in identifier names.
Python's advantage 3
Syntax is easier to read
Vlookup()
The Vlookup function can be used to compare a value that's between two values or for an exact value. The values of the first column must be in descending order. With this function, the comparison table is always read vertically.
Suppose cells A2:B20 contain a table with product numbers in column A and product prices in column B. What does the formula =VLOOKUP(A25,A2:B20,1,FALSE) return?
The number for the product in column A (or #N/A if the exact product number can't be found).
Suppose cells A2:B20 contain a table with sorted product numbers in column A and product prices in column B. What does the formula =VLOOKUP(A25,A2:B20,2) return?
The price for the product found in column A (or #N/A if the exact product number can't be found)
Suppose cells A2:B20 contain a table with product numbers in column A and product prices in column B. What does the formula =VLOOKUP(A25,A2:B20,2,FALSE) return?
The price for the product in column A if the exact product number corresponding to A25 can be found, or #N/A if not.
break
To break out of a loop
in
To check if a value is present in a list, tuple, etc.
continue
To continue to the next iteration of a loop
for
To create a for loop
while
To create a while loop
as
To create an alias
lambda
To create an anonymous function
global
To declare a global variable
nonlocal
To declare a non-local variable
class
To define a class
def
To define a function
del
To delete an object
yield
To end a function, returns a generator
return
To exit a function and return a value
import
To import a module
from
To import specific parts of a module
if
To make a conditional statement
try
To make a try...except statement
raise
To raise an exception
is
To test if two variables are equal
Is Python case sensitive while dealing with identifiers ?
True
bool("")
True
All the keywords except ___ are in lowercase and they must be written as it is.
True, False and None
Python's advantage 2
Typically involves less code (Built-in types and tools)
else
Used in conditional statements
elif
Used in conditional statements, same as else if
with
Used to simplify exception handling
finally
Used with exceptions, a block of code that will be executed no
except
Used with exceptions, what to do when an exception occurs
Python's advantage 4
Utilized by every major technology company (Python runs virtually every major platform used today)
Rules for writing identifiers 6
Variable names are case-sensitive
Rules for writing identifiers 4
We cannot use special symbols like !, @, $, % etc.
Python library is
a collection of functions and methods that allows you to perform many actions without writing your code.
extend()
add the elements of a list to the end of the current list
append()
adds an element at the end of the list
insert()
adds an element at the specified position
#Python has
an input function which lets you ask a user for some text input.
Variables do not need to be declared with
any particular type and can even change type after they have been set.
With the -- we can stop the loop before it has looped through all the items
break statement
The elif statement allows you to
check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.
Python's design philosophy emphasizes
code readability with its notable use of significant whitespace.
cmp(list1, list2)
compares elements of both lists
Variables are
containers for storing data values.
There can be any number of -, each followed by an indented block.
elif lines
len(list)
gives the total length of the list
matter
if there is an exception or not
How do you start writing an if statement in Python?
if x>y:
The -, -, and - lines are all aligned.
if, each elif, the final else
What is Python?
it is an interpreted, high-level, general-purpose programming language.
bool
logical value indicating True or False
float
numbers with a decimal point
tup
ordered immutable sequence of objects
str
ordered sequence of characters
list
ordered sequences of objects
What is a correct syntax to output "Hello World" in Python?
print("Hello World"), print('Hello World')
Which function displays a message on the screen in Python?
print()
clear()
removes all the elements from the list
pop()
removes the element at the specified position
remove()
removes the element at the specified position
copy()
returns a copy of the list
index()
returns the index of the first element with the specified value
count()
returns the number of elements with the specified value
reverse()
reverses the order of the list
sort()
sorts the list
You can specify a range of indexes by --.
specifying where to start and where to end the range.
Its language constructs and object-oriented approach aim
to help programmers write clear, logical code for small and large-scale projects.
Python allows you to assign values
to multiple variables in one line:
set
unordered collection of unique objects
dict
unordered key:Value pairs
int
whole numbers
How to swap two variables in one line ?
x,y=y,x
How do you create a variable with the numeric value 5?
x=int(5), x=5
dynamic typing means
you can reassign variables to different data types