100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
Lecture notes ENGG1810 €14,74   In winkelwagen

College aantekeningen

Lecture notes ENGG1810

 7 keer bekeken  0 keer verkocht
  • Vak
  • Instelling

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 essent...

[Meer zien]

Voorbeeld 4 van de 76  pagina's

  • 15 juni 2024
  • 76
  • 2023/2024
  • College aantekeningen
  • Vera chung
  • Alle colleges
avatar-seller
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.

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

√  	Verzekerd van kwaliteit door reviews

√ Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, Bancontact of creditcard voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper harryrickard. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €14,74. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 82265 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€14,74
  • (0)
  Kopen