Basic Python Workshop
Basic Python Workshop
PROGRAMMING
DATE:8 MARCH 2017
WHY PHYTON?
TO INCLUDE THE DOUBLE OR SINGLE QUOTE IN THE STRING, ESCAPE SEQUENCE LETTER \ IS
USED BEFORE THE QUOTES.
EG:
STRING OPERATION
Function Description
list.append(x) Add an item to the end of the list; equivalent
to a[len(a):] = [x].
list.extend(list2) Extend the list by appending all the items from
another list in the given list, i.e. list+list2
list.insert(i, x) Insert an item,x to a new position,i
list.remove(x) Remove the first item from the list whose value is x
list.pop(i) Remove the item at the given position in the list, and
return it.
list.index(x) Return the index in the list of the first item whose value
is x
list.count(x) Return the number of times x appears in the list
list.sort() Sort the items of the list in place
list.reverse() Reverse the elements of the list, in place.
LIST FILTERING
ASCII SEARCH
CONDITIONING (IF-ELSE)
PYTHON USE if, elif AND else, followed by a colon (:)
SPACING IS REQUIRED TO DEFINE THE CONDITION
NESTED IF IS POSSIBLE
FOR MULTIPLE CONDITIONS and / or IS USED
EXAMPLE:
LOOPING(WHILE)
SYNTAX
while(condition):
actions
change in condition
else CAN BE USE WITH while
EXECUTE AFTER THE WHILE LOOP DONE
SPACING IS REQUIRED TO DEFINE THE CONDITION
NESTED WHILE IS POSSIBLE
INFINITE LOOP CAN BE CREATED BY SIMPLY WRITING while(0)
THE INFINITE LOOP CAN BE TERMINATED BY SETTING A CONDITION
INSIDE THE PROGRAM CODE WITH break HOWEVER THE ACTION AFTER
else WILL NOT RUN
DURING RUNNING, THE INFINITE LOOP CAN BE TERMINATED BY PRESSING
CTRL + C
LOOPING (FOR)
SIMILAR TO while BUT ABLE TO ITERATE OVER THE
LIST OR STRING
else CAN BE USE WITH for
EXECUTE AFTER THE FOR LOOP DONE