PYTHON.pdf

PYTHON
LEARN
PREPARED BY: CLAUDINE MAE L. LEYSA, MIT
SCHOOL OF ICT
CONTENT
03
05
06
12
16
24
41
PYTHON INTRODUCTION
PYTHON KEYWORDS
PYTHON IDENTIFIERS
PYTHON COMMENTS
PYTHON VARIABLES, CONSTANTS AND LITERALS
PYTHON LITERAL COLLECTIONS
PYTHON DATA TYPES
WHY PYTHON
It is a high-level, general-purpose
programming language
released in 1991
by Guido van Rossum.
Python is an interpreted language, meaning
that it does not need to be compiled before
it can be run.
This makes it ideal for scripting, prototyping,
and rapid development, as changes to the
code can be quickly tested without the need
for a lengthy compile step.
PYTHON KEYWORDS
Keywords are predefined, reserved words used in Python programming that
have special meanings to the compiler.
We cannot use a keyword as a variable name, function name, or any other
identifier. They are used to define the syntax and structure of the Python
language.
All the keywords except True, False and None are in lowercase and they must
be written as they are.
PYTHON KEYWORDS
PYTHON IDENTIFIERS
Identifiers are the name given to variables, classes, methods, etc.
Here, language is a variable (an identifier) which holds the value
'Python'. We cannot use keywords as variable names as they are
reserved names that are built-in to Python.
The above code is wrong because we have used continue as a
variable name.
PYTHON IDENTIFIERS
Identifiers cannot be a keyword.
Identifiers are case-sensitive.
It can have a sequence of letters and digits. However,
it must begin with a letter or _. The first letter of an
identifier cannot be a digit.
It's a convention to start an identifier with a letter
rather _.
Whitespaces are not allowed.
We cannot use special symbols like !, @, #, $, and so
on.
Rules for Naming an Identifier
VALID AND INVALID IDENTIFIERS IN PYTHON
THINGS TO REMEMBER
Python is a case-sensitive language. This means, Variable and
variable are not the same.
Always give the identifiers a name that makes sense. While c
= 10 is a valid name, writing count = 10 would make more
sense, and it would be easier to figure out what it represents
when you look at your code after a long gap.
Multiple words can be separated using an underscore, like
this_is_a_long_variable.
YOUR FIRST PROGRAM
print ("I love to learn Python")
print ('I love to learn Python')
DECLARING VARIABLES
declare and initialize two variables
print the output
name= "Python"
Age= 4
print(name)
PYTHON COMMENTS
In computer programming, comments are hints that we
use to make our code more understandable. Comments
are completely ignored by the interpreter.
#this is a comment
TYPES OF COMMENTS IN PYTHON
single-line comment
multi-line comment
In Python, there are two types of comments:
SINGLE LINE COMMENT
A single-line comment starts and ends in the same
line. We use the # symbol to write a single-line
comment.
MULTI-LINE COMMENT IN PYTHON
Python doesn't offer a separate way to write multiline comments.
However, there are other ways to get around this issue.
We can use # at the beginning of each line of comment on multiple lines.
Another way of doing this is to use triple quotes, either ''' or """
PYTHON VARIABLES, CONSTANTS AND LITERALS
PYTHON VARIABLES
In programming, a variable is a container (storage area) to hold data.
In programming, a variable is a container (storage area) to hold data.
As we can see from the above example, we use the assignment operator = to assign
a value to a variable.
CHANGING THE VALUE OF A VARIABLE IN PYTHON
In this part of the code, you're creating a variable site_name
and assigning it the value 'programiz.pro'. Then, you're using
the print function to display the value of the site_name
variable.
Here, you're reassigning a new value 'apple.com' to the
site_name variable. This line of code replaces the previous
value 'programiz.pro'. After the reassignment, when you print
the site_name variable again, you will see the new value:
The variable site_name is initially assigned the value 'programiz.pro'.
You print the value of site_name, which outputs 'programiz.pro'.
You reassign the variable site_name with the value 'apple.com'.
You print the value of site_name again, which now outputs 'apple.com'.
ASSIGNING MULTIPLE VALUES TO MULTIPLE VARIABLES
a is assigned the value 5
b is assigned the value 3.2
c is assigned the value 'Hello'
In this line of code, you're declaring three variables a,
b, and c, and you're assigning values to them using a
technique called unpacking.
The values being assigned are 5, 3.2, and 'Hello',
respectively. Python automatically assigns each
value to its corresponding variable based on their
positions.
After this line of code, the variables have the
following values:
Then, you use the print function to output the values
of these variables
ASSIGNING MULTIPLE VARIABLES AT ONCE
In this line of code, you are assigning the value 'programiz.com' to both the variables
site1 and site2. This is achieved using multiple assignment, where the same value is
assigned to multiple variables in a single line.
After this line of code, both site1 and site2 contain the value 'programiz.com'.
Then, you use the print function to output the values of both variables:
PYTHON IS CASE-SENSITIVE
Python is case-sensitive. So num and Num are different variables.
PYTHON LITERAL
Literals are representations of fixed values in a program. They can
be numbers, characters, or strings, etc. For example, 'Hello, World!',
12, 23.0, 'C', etc.
Literals are often used to assign values to variables or constants.
PYTHON NUMERIC LITERALS
Numeric Literals are immutable (unchangeable). Numeric literals can belong to 3
different numerical types: Integer, Float, and Complex.
PYTHON BOOLEAN LITERALS
There are two boolean literals: True and False.
PYTHON LITERAL
STRING AND CHARACTER LITERALS IN
PYTHON
Here, S is a character literal assigned to some_character.
Similarly, String literals are sequences of Characters enclosed in quotation marks.
Here, 'Python is fun' is a string literal assigned to some_string.
LITERAL
COLLECTIONS
PYTHON
SCHOOL OF ICT
LITERAL COLLECTIONS
List literals
Tuple literals
Dict literals
Set literals.
There are four different
literal collections:
LIST LITERAL
A tuple is a collection of different data-type.
It is enclosed by the parentheses ‘()‘ and each element
is separated by the comma(,).
It is immutable.
LIST LITERAL
fruits ---- variable
append ---- adding an element
remove ---- removing an
element
variable[index] ----- accessing
the elements
variable[index] = element ----
modifying the element
PRACTICE EXERCISES
Task 1: Create a list of your favorite colors using a list
literal. ( 4 colors. Use favorite colors as the variable)
Task 2: Add a new color to the list
Task 3. Modify the element in index 3
Task 4: Print the second color in the list
Task 5: Iterate through the list and print each favorite
color
Task 6. Check if "any color you want" is in the list of
favorite colors
LIST LITERAL
TUPLE LITERAL
List literals are written within square brackets [ ].
Lists work similarly to strings -- use the len() function
and square brackets [ ] to access data, with the first
element at index 0.
TUPLE LITERAL
person ---- variable
variable[index] ----- accessing
the elements
tuple has no remove attribute
TUPLE LITERAL
book_info ---- variable
variable[index] ----- accessing the elements
tuple has no remove attribute
TUPLE LITERAL
You can't modify a tuple directly, so create a
new one.
TUPLE LITERAL
book_info ---- variable
variable[index] ----- accessing the
elements
tuple has no remove attribute
add_book_info ---- new variable
PRACTICE EXERCISES
Task 1: Create a tuple containing the names of four
countries
Task 2: Task 2: Print the second country in the tuple
Task 3. Check if 'Germany' is in the tuple of countries
Task 4: Iterate through the tuple and print each country
Task 5: Attempt to change an element in the tuple (this
should result in an error)
TUPLE LITERAL
DICTIONARY LITERAL
The dictionary stores the data in the key-value pair. It
is enclosed by curly braces ‘{}‘ and each pair is
separated by the commas(,).
We can store different types of data in a dictionary.
'Dictionaries are mutable.
DICTIONARY LITERAL
person ---- variable
variable['keys'] -----
accessing the elements
PRACTICE EXERCISES
Task 1: Creating a dictionary using a dictionary
literal car
May Include the brand, model, year and color
Task 2: Accessing values in the dictionary
DICTIONARY LITERAL
SET LITERAL
Set is the collection of the unordered data set. It is
enclosed by the {} and each element is separated by
the comma(,).
SET LITERAL
vowels & fruits ---- variable
Sets in Python are implemented as hash tables, which are designed
for fast membership tests and elimination of duplicates.
SET LITERAL
fruits ---- variable
add ---- add another
element
remove/discard ----
removing an element
Boolean ---- True/False
PRACTICE EXERCISES
Task 1: Create a set of programming languages (4)
Task 2: Add a new programming language to the set
Task 3: Remove 'a programming language' from the set
Task 4: Check if 'that programming language' is in the
set
Task 5: Print the updated set of programming
languages
SET LITERAL
DATA TYPES
PYTHON
SCHOOL OF ICT
DATA TYPES
In computer programming, data types specify the
type of data that can be stored inside a variable.
Here, 24 (an integer) is assigned to the num variable.
So the data type of num is of the int class.
DATA TYPES
DATA TYPES
PRACTICE EXERCISES
x = {"name" : "John", "age" : 36}
code = "Hello World"
places = ["Pototan", "Aklan", "Roxas"]
type = bytearray(6)
z = b"Data Structures"
1.
2.
3.
4.
5.
FIND THE DATA TYPE
PYTHON NUMERIC DATA TYPE
In Python, numeric data type is used to hold numeric values.
Integers, floating-point numbers and complex numbers fall under Python numbers
category. They are defined as int, float and complex classes in Python.
int - holds signed integers of non-limited length.
float - holds floating decimal points and it's accurate up to 15 decimal places.
complex - holds complex numbers.
We can use the type() function to know which class a variable or a value belongs to.
https://www.programiz.com/python-programming/keywords-identifier
https://www.geeksforgeeks.org/literals-in-python/
https://www.tutorialspoint.com/python/
https://www.w3schools.com/python/python_datatypes.asp
REFERENCES
1 von 48

Recomendados

L6 - Loops.pptx von
L6 - Loops.pptxL6 - Loops.pptx
L6 - Loops.pptxEloAOgardo
15 views29 Folien
L6 - Loops.pptx von
L6 - Loops.pptxL6 - Loops.pptx
L6 - Loops.pptxEloAOgardo
8 views29 Folien
L5 - Data Types, Keywords.pptx von
L5 - Data Types, Keywords.pptxL5 - Data Types, Keywords.pptx
L5 - Data Types, Keywords.pptxEloAOgardo
12 views29 Folien
Python - Module 1.ppt von
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.pptjaba kumar
27 views42 Folien
Python Introduction von
Python IntroductionPython Introduction
Python Introductionvikram mahendra
97 views43 Folien
Python Data Types von
Python Data TypesPython Data Types
Python Data Typesathithanvijay
210 views20 Folien

Más contenido relacionado

Similar a PYTHON.pdf

Python basics von
Python basicsPython basics
Python basicsManisha Gholve
137 views39 Folien
Introduction to Python for Data Science and Machine Learning von
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning ParrotAI
566 views64 Folien
Unit 2 python von
Unit 2 pythonUnit 2 python
Unit 2 pythonpraveena p
362 views93 Folien
Python (3).pdf von
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
23 views30 Folien
Python fundamentals von
Python fundamentalsPython fundamentals
Python fundamentalsnatnaelmamuye
92 views69 Folien
Python Objects von
Python ObjectsPython Objects
Python ObjectsMuhammadBakri13
923 views22 Folien

Similar a PYTHON.pdf(20)

Introduction to Python for Data Science and Machine Learning von ParrotAI
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI566 views
Python - An Introduction von Swarit Wadhe
Python - An IntroductionPython - An Introduction
Python - An Introduction
Swarit Wadhe4.5K views
Zero to Hero - Introduction to Python3 von Chariza Pladin
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
Chariza Pladin7.6K views
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf von KosmikTech1
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech133 views
Python interview questions and answers von RojaPriya
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya149 views
Python interview questions and answers von kavinilavuG
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
kavinilavuG118 views
Python introduction towards data science von deepak teja
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
deepak teja131 views

Último

Listed Instruments Survey 2022.pptx von
Listed Instruments Survey  2022.pptxListed Instruments Survey  2022.pptx
Listed Instruments Survey 2022.pptxsecretariat4
52 views12 Folien
Data about the sector workshop von
Data about the sector workshopData about the sector workshop
Data about the sector workshopinfo828217
29 views27 Folien
[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo... von
[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo...[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo...
[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo...DataScienceConferenc1
9 views77 Folien
OPPOTUS - Malaysians on Malaysia 3Q2023.pdf von
OPPOTUS - Malaysians on Malaysia 3Q2023.pdfOPPOTUS - Malaysians on Malaysia 3Q2023.pdf
OPPOTUS - Malaysians on Malaysia 3Q2023.pdfOppotus
27 views19 Folien
Dr. Ousmane Badiane-2023 ReSAKSS Conference von
Dr. Ousmane Badiane-2023 ReSAKSS ConferenceDr. Ousmane Badiane-2023 ReSAKSS Conference
Dr. Ousmane Badiane-2023 ReSAKSS ConferenceAKADEMIYA2063
5 views34 Folien
META.pptx von
META.pptxMETA.pptx
META.pptxvasanthan19012003
6 views10 Folien

Último(20)

Listed Instruments Survey 2022.pptx von secretariat4
Listed Instruments Survey  2022.pptxListed Instruments Survey  2022.pptx
Listed Instruments Survey 2022.pptx
secretariat452 views
Data about the sector workshop von info828217
Data about the sector workshopData about the sector workshop
Data about the sector workshop
info82821729 views
[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo... von DataScienceConferenc1
[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo...[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo...
[DSC Europe 23][DigiHealth] Muthu Ramachandran AI and Blockchain Framework fo...
OPPOTUS - Malaysians on Malaysia 3Q2023.pdf von Oppotus
OPPOTUS - Malaysians on Malaysia 3Q2023.pdfOPPOTUS - Malaysians on Malaysia 3Q2023.pdf
OPPOTUS - Malaysians on Malaysia 3Q2023.pdf
Oppotus27 views
Dr. Ousmane Badiane-2023 ReSAKSS Conference von AKADEMIYA2063
Dr. Ousmane Badiane-2023 ReSAKSS ConferenceDr. Ousmane Badiane-2023 ReSAKSS Conference
Dr. Ousmane Badiane-2023 ReSAKSS Conference
AKADEMIYA20635 views
Best Home Security Systems.pptx von mogalang
Best Home Security Systems.pptxBest Home Security Systems.pptx
Best Home Security Systems.pptx
mogalang9 views
[DSC Europe 23] Ales Gros - Quantum and Today s security with Quantum.pdf von DataScienceConferenc1
[DSC Europe 23] Ales Gros - Quantum and Today s security with Quantum.pdf[DSC Europe 23] Ales Gros - Quantum and Today s security with Quantum.pdf
[DSC Europe 23] Ales Gros - Quantum and Today s security with Quantum.pdf
CRM stick or twist.pptx von info828217
CRM stick or twist.pptxCRM stick or twist.pptx
CRM stick or twist.pptx
info82821711 views
Short Story Assignment by Kelly Nguyen von kellynguyen01
Short Story Assignment by Kelly NguyenShort Story Assignment by Kelly Nguyen
Short Story Assignment by Kelly Nguyen
kellynguyen0120 views
Ukraine Infographic_22NOV2023_v2.pdf von AnastosiyaGurin
Ukraine Infographic_22NOV2023_v2.pdfUkraine Infographic_22NOV2023_v2.pdf
Ukraine Infographic_22NOV2023_v2.pdf
AnastosiyaGurin1.4K views
[DSC Europe 23] Predrag Ilic & Simeon Rilling - From Data Lakes to Data Mesh ... von DataScienceConferenc1
[DSC Europe 23] Predrag Ilic & Simeon Rilling - From Data Lakes to Data Mesh ...[DSC Europe 23] Predrag Ilic & Simeon Rilling - From Data Lakes to Data Mesh ...
[DSC Europe 23] Predrag Ilic & Simeon Rilling - From Data Lakes to Data Mesh ...
SUPER STORE SQL PROJECT.pptx von khan888620
SUPER STORE SQL PROJECT.pptxSUPER STORE SQL PROJECT.pptx
SUPER STORE SQL PROJECT.pptx
khan88862013 views
Product Research sample.pdf von AllenSingson
Product Research sample.pdfProduct Research sample.pdf
Product Research sample.pdf
AllenSingson33 views
CRM stick or twist workshop von info828217
CRM stick or twist workshopCRM stick or twist workshop
CRM stick or twist workshop
info82821714 views

PYTHON.pdf

  • 1. PYTHON LEARN PREPARED BY: CLAUDINE MAE L. LEYSA, MIT SCHOOL OF ICT
  • 2. CONTENT 03 05 06 12 16 24 41 PYTHON INTRODUCTION PYTHON KEYWORDS PYTHON IDENTIFIERS PYTHON COMMENTS PYTHON VARIABLES, CONSTANTS AND LITERALS PYTHON LITERAL COLLECTIONS PYTHON DATA TYPES
  • 3. WHY PYTHON It is a high-level, general-purpose programming language released in 1991 by Guido van Rossum. Python is an interpreted language, meaning that it does not need to be compiled before it can be run. This makes it ideal for scripting, prototyping, and rapid development, as changes to the code can be quickly tested without the need for a lengthy compile step.
  • 4. PYTHON KEYWORDS Keywords are predefined, reserved words used in Python programming that have special meanings to the compiler. We cannot use a keyword as a variable name, function name, or any other identifier. They are used to define the syntax and structure of the Python language. All the keywords except True, False and None are in lowercase and they must be written as they are.
  • 6. PYTHON IDENTIFIERS Identifiers are the name given to variables, classes, methods, etc. Here, language is a variable (an identifier) which holds the value 'Python'. We cannot use keywords as variable names as they are reserved names that are built-in to Python. The above code is wrong because we have used continue as a variable name.
  • 7. PYTHON IDENTIFIERS Identifiers cannot be a keyword. Identifiers are case-sensitive. It can have a sequence of letters and digits. However, it must begin with a letter or _. The first letter of an identifier cannot be a digit. It's a convention to start an identifier with a letter rather _. Whitespaces are not allowed. We cannot use special symbols like !, @, #, $, and so on. Rules for Naming an Identifier
  • 8. VALID AND INVALID IDENTIFIERS IN PYTHON
  • 9. THINGS TO REMEMBER Python is a case-sensitive language. This means, Variable and variable are not the same. Always give the identifiers a name that makes sense. While c = 10 is a valid name, writing count = 10 would make more sense, and it would be easier to figure out what it represents when you look at your code after a long gap. Multiple words can be separated using an underscore, like this_is_a_long_variable.
  • 10. YOUR FIRST PROGRAM print ("I love to learn Python") print ('I love to learn Python')
  • 11. DECLARING VARIABLES declare and initialize two variables print the output name= "Python" Age= 4 print(name)
  • 12. PYTHON COMMENTS In computer programming, comments are hints that we use to make our code more understandable. Comments are completely ignored by the interpreter. #this is a comment
  • 13. TYPES OF COMMENTS IN PYTHON single-line comment multi-line comment In Python, there are two types of comments:
  • 14. SINGLE LINE COMMENT A single-line comment starts and ends in the same line. We use the # symbol to write a single-line comment.
  • 15. MULTI-LINE COMMENT IN PYTHON Python doesn't offer a separate way to write multiline comments. However, there are other ways to get around this issue. We can use # at the beginning of each line of comment on multiple lines. Another way of doing this is to use triple quotes, either ''' or """
  • 16. PYTHON VARIABLES, CONSTANTS AND LITERALS PYTHON VARIABLES In programming, a variable is a container (storage area) to hold data. In programming, a variable is a container (storage area) to hold data. As we can see from the above example, we use the assignment operator = to assign a value to a variable.
  • 17. CHANGING THE VALUE OF A VARIABLE IN PYTHON In this part of the code, you're creating a variable site_name and assigning it the value 'programiz.pro'. Then, you're using the print function to display the value of the site_name variable. Here, you're reassigning a new value 'apple.com' to the site_name variable. This line of code replaces the previous value 'programiz.pro'. After the reassignment, when you print the site_name variable again, you will see the new value: The variable site_name is initially assigned the value 'programiz.pro'. You print the value of site_name, which outputs 'programiz.pro'. You reassign the variable site_name with the value 'apple.com'. You print the value of site_name again, which now outputs 'apple.com'.
  • 18. ASSIGNING MULTIPLE VALUES TO MULTIPLE VARIABLES a is assigned the value 5 b is assigned the value 3.2 c is assigned the value 'Hello' In this line of code, you're declaring three variables a, b, and c, and you're assigning values to them using a technique called unpacking. The values being assigned are 5, 3.2, and 'Hello', respectively. Python automatically assigns each value to its corresponding variable based on their positions. After this line of code, the variables have the following values: Then, you use the print function to output the values of these variables
  • 19. ASSIGNING MULTIPLE VARIABLES AT ONCE In this line of code, you are assigning the value 'programiz.com' to both the variables site1 and site2. This is achieved using multiple assignment, where the same value is assigned to multiple variables in a single line. After this line of code, both site1 and site2 contain the value 'programiz.com'. Then, you use the print function to output the values of both variables:
  • 20. PYTHON IS CASE-SENSITIVE Python is case-sensitive. So num and Num are different variables.
  • 21. PYTHON LITERAL Literals are representations of fixed values in a program. They can be numbers, characters, or strings, etc. For example, 'Hello, World!', 12, 23.0, 'C', etc. Literals are often used to assign values to variables or constants. PYTHON NUMERIC LITERALS Numeric Literals are immutable (unchangeable). Numeric literals can belong to 3 different numerical types: Integer, Float, and Complex. PYTHON BOOLEAN LITERALS There are two boolean literals: True and False.
  • 23. STRING AND CHARACTER LITERALS IN PYTHON Here, S is a character literal assigned to some_character. Similarly, String literals are sequences of Characters enclosed in quotation marks. Here, 'Python is fun' is a string literal assigned to some_string.
  • 25. LITERAL COLLECTIONS List literals Tuple literals Dict literals Set literals. There are four different literal collections:
  • 26. LIST LITERAL A tuple is a collection of different data-type. It is enclosed by the parentheses ‘()‘ and each element is separated by the comma(,). It is immutable.
  • 27. LIST LITERAL fruits ---- variable append ---- adding an element remove ---- removing an element variable[index] ----- accessing the elements variable[index] = element ---- modifying the element
  • 28. PRACTICE EXERCISES Task 1: Create a list of your favorite colors using a list literal. ( 4 colors. Use favorite colors as the variable) Task 2: Add a new color to the list Task 3. Modify the element in index 3 Task 4: Print the second color in the list Task 5: Iterate through the list and print each favorite color Task 6. Check if "any color you want" is in the list of favorite colors LIST LITERAL
  • 29. TUPLE LITERAL List literals are written within square brackets [ ]. Lists work similarly to strings -- use the len() function and square brackets [ ] to access data, with the first element at index 0.
  • 30. TUPLE LITERAL person ---- variable variable[index] ----- accessing the elements tuple has no remove attribute
  • 31. TUPLE LITERAL book_info ---- variable variable[index] ----- accessing the elements tuple has no remove attribute
  • 32. TUPLE LITERAL You can't modify a tuple directly, so create a new one.
  • 33. TUPLE LITERAL book_info ---- variable variable[index] ----- accessing the elements tuple has no remove attribute add_book_info ---- new variable
  • 34. PRACTICE EXERCISES Task 1: Create a tuple containing the names of four countries Task 2: Task 2: Print the second country in the tuple Task 3. Check if 'Germany' is in the tuple of countries Task 4: Iterate through the tuple and print each country Task 5: Attempt to change an element in the tuple (this should result in an error) TUPLE LITERAL
  • 35. DICTIONARY LITERAL The dictionary stores the data in the key-value pair. It is enclosed by curly braces ‘{}‘ and each pair is separated by the commas(,). We can store different types of data in a dictionary. 'Dictionaries are mutable.
  • 36. DICTIONARY LITERAL person ---- variable variable['keys'] ----- accessing the elements
  • 37. PRACTICE EXERCISES Task 1: Creating a dictionary using a dictionary literal car May Include the brand, model, year and color Task 2: Accessing values in the dictionary DICTIONARY LITERAL
  • 38. SET LITERAL Set is the collection of the unordered data set. It is enclosed by the {} and each element is separated by the comma(,).
  • 39. SET LITERAL vowels & fruits ---- variable Sets in Python are implemented as hash tables, which are designed for fast membership tests and elimination of duplicates.
  • 40. SET LITERAL fruits ---- variable add ---- add another element remove/discard ---- removing an element Boolean ---- True/False
  • 41. PRACTICE EXERCISES Task 1: Create a set of programming languages (4) Task 2: Add a new programming language to the set Task 3: Remove 'a programming language' from the set Task 4: Check if 'that programming language' is in the set Task 5: Print the updated set of programming languages SET LITERAL
  • 43. DATA TYPES In computer programming, data types specify the type of data that can be stored inside a variable. Here, 24 (an integer) is assigned to the num variable. So the data type of num is of the int class.
  • 46. PRACTICE EXERCISES x = {"name" : "John", "age" : 36} code = "Hello World" places = ["Pototan", "Aklan", "Roxas"] type = bytearray(6) z = b"Data Structures" 1. 2. 3. 4. 5. FIND THE DATA TYPE
  • 47. PYTHON NUMERIC DATA TYPE In Python, numeric data type is used to hold numeric values. Integers, floating-point numbers and complex numbers fall under Python numbers category. They are defined as int, float and complex classes in Python. int - holds signed integers of non-limited length. float - holds floating decimal points and it's accurate up to 15 decimal places. complex - holds complex numbers. We can use the type() function to know which class a variable or a value belongs to.