You are on page 1of 9

Python Programming 2

Mohamad Sadra Salman Noori


Python 2 Class
• 30 Weeks, 30 Sessions
– Study before each session
• Course + Examples
• Homework
– Once a week
– File name must be like: number.py inside firstname-Lastname.zip
– Deadline Friday 12pm
• Solving Homework
– Every Week(if needed)
• Presentation
– Every week 10 min
• Exam
– Last Week
• Projects
– One Project James Tam
• IDE
Python Topics
• Tuple/Set
• Mutable/Immutable
• Recursive Function
• Scope
• Bitwise Operation
• Encoding
• File and Folder Manipulation
• Stack/Queue
• Search/Sort/Stack/Heap
• Object Oriented/Class/Inheritance
• Database/MongoDB/robomongo
• DateTime
• Socket Programming
• Regular Expressions
•MultiThreading/MultiProcessing
• PyQT James Tam
Python Programming 2
• What is IDE?
– Integrated Development Environment
– Automation support
– Highlighting of keywords, errors
– Debugging
– VSCode

• Debug
– Trace automatically
– Breakpoints

• Code Complexity
– Efficient CPU and RAM usage

• Practice online activities


– Search for errors

James Tam
Mutable / Immutable
• Immutable object can’t be changed after it is created
– int, float, bool, string and tuple

• Mutable object can be changed after it is created


– List, dict and set

• S = “sadra”
• S[-1] = “i”
• Error!

• How integer is immutable???

• L = [6,0]
• L[0] = 4
• No Error
James Tam
Tuple
 Ordered, unchangable collection

 myTuple = (“1”, 2, 3)
x = ("apple", "banana", "cherry")
y = list(x)
 Indexing and looping and checking existence of y[1] = "kiwi"
x = tuple(y)
item is just like list
print(len(x))
Z=(1,)
 Add, Remove and change items are not allowed
T3 = T1 + T2

 Join tuples with +

James Tam
Set
x = ("apple", "banana", "cherry")
 Unordered, unindexed and unchangeable collection y = list(x)
y[1] = "kiwi"
x = tuple(y)
 mySet = {“1”, 2, 3}
print(len(x))
Z=(1,)
 looping and checking existence of item is just like list T3 = T1 + T2

mySet = {1,2}
 Once a set is created, you cannot change its items, mySet.add(“’3’”)
but you can add new items. mySet.update([“apple”,4])
mySet.remove(3)
mySet.discard(3)
 Clear, del, union and etc mySet.pop()

print(len(mySet))

James Tam
Debug
• Debugging is tracing code automatically
– Interactive code
– Complex code
– Error debugging

• IDEs have debugger

• Breakpoints

• Watch

James Tam
Homework
• Write a Python program to sort a tuple by its float element

• Write a Python program to convert a list of tuples into a dictionary

• Write a Python program that calculate requested items with 2 given sets
– Union
– Intersection
– Disjunctive Union
– Check if is subset

• Write a Python program that calculate red parts of three given sets

James Tam

You might also like