0% found this document useful (0 votes)
5 views

Lecture03 - Basic Grammar (data, list, dic)

This document outlines basic grammar in Python, focusing on data types such as integers, floats, strings, booleans, lists, tuples, dictionaries, and sets. It emphasizes the importance of these data structures in managing and analyzing datasets in biomedical engineering. The document also includes exercises and quizzes to reinforce learning.

Uploaded by

dtp09121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture03 - Basic Grammar (data, list, dic)

This document outlines basic grammar in Python, focusing on data types such as integers, floats, strings, booleans, lists, tuples, dictionaries, and sets. It emphasizes the importance of these data structures in managing and analyzing datasets in biomedical engineering. The document also includes exercises and quizzes to reinforce learning.

Uploaded by

dtp09121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Python: Basic Grammar (Part 2)

Instructor: Kisoo Kim

Department of Biomedical Engineering


Kyung Hee University

1
Learning goal

“In biomedical engineering, we manage, analyze, and create datasets.

Python enables us to efficiently handle various dataset-related tasks.”

Learning goals are


• To learn basic data types in python
• Understand data structure
• To learn how to utilize datasets

2
Data Type

• Integers: whole numbers that can be negative or positive


1, -10, 3, 5, 100, …

• Floats: negative or positive numbers, which contains a decimal point


1.0, 4.0, 10.111, 0.3333

• Strings: multiple characters


Kim, BME213, Python, …

• Boolean: represents scenarios with two outcomes


True (1), False (0)

3
Data Type

4
String

5
How can we save/handle data to a single variable?

Let’s learn
• List
• Tuple
• Dictionary
• Set

6
List

• A List is defined by square brackets [, ]

• The individual entries can be the different type

• List indexing: able to access to a certain position of


data in the list

7
List

8
Tuple Tuples are fixed size in nature whereas lists are dynamic.
In other words, a tuple is immutable whereas a list is mutable.

A tuple is rather similar to a list, but is defined using round


brackets, (, )

o Performance:
• Tuples are faster than lists. Use a tuple when dealing
with a fixed set of values that will only be iterated
through.

o Immutability & Safety:


• Tuples help “write-protect” data that should remain
unchanged.
• Using a tuple instead of a list acts as an implicit
assertion of immutability.
• Modifying a tuple requires intentional effort, ensuring
data integrity.

o Dictionary Keys:
• Tuples with only immutable elements (e.g., strings,
numbers, other tuples) can be used as dictionary keys.
• Lists cannot be used as dictionary keys because they
are mutable.

9
Tuple

Quiz:

a = 2, 4, 5, 5, ’x’, ’y’

len(a) Ans:
a.count(5) Ans:
a.index(‘x’) Ans:

10
Dictionary a = dict()
a = {}

• Dictionaries provide a mechanism for


storing data labelled with a keyword or
other information

• This consists of “key : value”

11
Dictionary

We can make a list with dictionaries

12
Dictionary

13
Exercise

1. Create the dictionary


{‘a’: 11, ‘b’: 13, ‘c’: 21, ‘d’: 29}

2. Using a function, calculate the sum of values in the dictionary

14
Set
‘Set’ is not commonly encountered but can be very useful. It implements the mathematical
concept of a set. A set can be created from a tuple or list.

set1 set2

15
QUIZ

1. Write the type of ‘a’ 2. How to make a joining sets into one new set,
called set5, using set1, set2, set3, set4?
o a = (1,2,3,4,5)

o a = [1,2,3,4,5]

o a = {1,2,3,4,5}

16
Summary

17

You might also like