Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Lecture notes ENGG1810

Rating
-
Sold
-
Pages
76
Uploaded on
15-06-2024
Written in
2023/2024

Enhance your understanding of Python programming with these detailed ENGG1810 USYD course notes. This document is designed to support students in grasping the fundamentals of Python and advancing through more complex topics effectively. Ideal for students and professionals, these notes cover essential programming concepts and data structures. Key Features: Data Structures: Detailed explanations and examples on manipulating lists, tuples, sets, and dictionaries. Control Flow: Insights into using conditional statements, loops, and functions to control the flow of programs. File Operations: Techniques for file reading, writing, and error handling to manage data effectively. Advanced Topics: Guides on utilizing Python for complex data structures and command line arguments. Modules and Libraries: Advice on creating and using Python modules to improve code modularity and reusability. The notes are formatted in a clear, concise manner, making them easy to follow and ideal for quick referencing. Each section is coupled with practical code examples that reinforce learning and application. Utility: These notes are a great resource for exam preparation, project reference, or as a comprehensive guide to learning Python programming from the ground up. They provide a structured approach to understanding both foundational and advanced Python topics. Accessibility: Available in PDF format, the notes can be easily accessed and read on any device, facilitating learning on the go or during dedicated study sessions. Recommended For: Students enrolled in ENGG1810 or related programming courses. Individuals self-studying Python. Professionals looking to refresh their programming knowledge. Incorporate these notes into your educational resources for a solid understanding of Python programming, helping you to excel in your studies and professional projects.

Show more Read less
Institution
Course

Content preview

ENG1810 Notes
Lecture 2

Lists

● Definition: Lists are mutable, ordered collections of items, allowing duplicates.
● Examples and Operations:
○ Creating and accessing lists:
computer = ['imac', 'alienware', 'inspiron', 'blade']
print(computer[1]) # Output: alienware

○ Adding items:
computer.append('macbook') # Adds at the end
computer.insert(1, 'macbook') # Inserts at index 1

○ Removing items:
computer.remove('inspiron') # Removes 'inspiron'
computer.pop(3) # Removes the fourth item

○ Modifying lists:
computer[3] = 'razer_blade' # Changes 'blade' to 'razer_blade'
Tuples

● Definition: Tuples are immutable, ordered collections that allow duplicate values.
● Operations:
○ Accessing tuples:
my_family = ('mother', 'father', 'sister', 'me')
print(my_family[2]) # Output: sister

○ Modifying tuples (indirectly by converting to a list):
temp_list = list(my_family)
temp_list.append('brother')
my_family = tuple(temp_list)
Sets

● Definition: Sets are unordered, unindexed collections that do not allow duplicates.
● Operations:
○ Adding and removing items:


my_family = {'mother', 'father', 'sister', 'me'}
my_family.add('uncle')
my_family.remove('sister')

,Dictionaries

● Definition: Dictionaries store key-value pairs and are mutable and ordered (as of python
3.7).
● Examples:
○ Creating and accessing dictionaries:
computer = {'brand': 'Apple', 'model': 'iMac', 'year': 2007}
print(computer['model']) # Output: iMac

○ Modifying dictionaries:
computer['year'] = 2010 # Updates the year
computer['color'] = 'silver' # Adds a new key-value pair


Basics of Control Flow
● Control flow in programming refers to the direction in which the program executes. In
Python, this is primarily managed through conditional statements and loops. This lecture
focuses on conditional statements which allow the program to react differently depending
on the input or other data.
Conditional Statements
Conditional statements are the backbone of decision making in Python. They execute a certain
block of code based on a condition. The primary statements used are:

1. if Statement:
○ The if statement is used to test a condition and execute a block of code if the
condition is true.
○ Syntax:
if condition:
# execute this block

○ Example:
if weather == 'sunny':
print("Let's go outside!")

2. else Statement:
○ The else statement follows an if statement and is executed if the if statement’s
condition is false.
○ Syntax:
if condition:
# execute this block
else:
# execute this block

○ Example:

, if weather == 'sunny':
print("Let's go outside!")
else:
print("We might need an umbrella.")

3. elif (else if) Statement:
○ The elif statement is used to check multiple expressions for TRUE and execute a
block of code as soon as one of the conditions evaluates to TRUE.
○ Unlike else, there can be multiple elif blocks following an if.
○ Syntax:
if condition1:
# execute block 1
elif condition2:
# execute block 2
else:
# execute block 3

○ Example:
if weather == 'sunny':
print("Let's go outside!")
elif weather == 'rainy':
print("We need an umbrella.")
else:
print("It's a pleasant day.")

, Lecture 3
While Loops

● A while loop in Python repeatedly executes a target statement as long as a given
condition is true. Here’s how you structure a while loop:
○ while <condition>:
# Execute these actions

● Example: Counting Race Finishers Imagine a scenario where athletes are finishing a
race, and we want to print their finish positions as they cross the line:
○ person = 0
while person < 100:
person += 1
print(person)
● This code will print numbers 1 through 100, simulating athletes finishing from 1st to
100th place.
For Loops

● A for loop is used for iterating over a collection (like a list, tuple, set, or dictionary) or an
iterator. The basic syntax of a for loop is:
● for variable in collection:
# Execute actions




● Example: Iterating Over a List of Students
● students = ['Caren Han', 'Henry Weld', 'Annie Sun', 'Lilian Hunt']
for student in students:
print(student)

● This will print each student's name from the list.

Written for

Institution
Course

Document information

Uploaded on
June 15, 2024
Number of pages
76
Written in
2023/2024
Type
Class notes
Professor(s)
Vera chung
Contains
All classes

Subjects

$15.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
harryrickard

Get to know the seller

Seller avatar
harryrickard University of Sydney
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions