Hello Readers,
Here we are Day 14 of #90daysofdevops
👣 Topics for #day14
Data Types
Data Structures
Tasks of Day 14
Data Types
Python Data Types are used to define the type of a variable. It defines what type of data we are going to store in a variable. The data stored in memory can be of many types. For example, a person's age is stored as a numeric value and his or her address is stored as alphanumeric characters.
Text Type: |
|
Numeric Types: |
|
Sequence Types: |
|
Mapping Type: |
|
Set Types: |
|
Boolean Type: |
|
Binary Types: |
|
None Type: |
|
Data Structures
A data structure is a way of organizing and storing data in a computer's memory so that it can be accessed and manipulated efficiently.Different data structures are used for different types of data and different operations.
So for example, if you need to store a collection of elements and perform operations like inserting or deleting elements, a list or a linked list may be suitable.
Python provides a range of built-in data structures, including lists, tuples, sets, and dictionaries, as well as support for more complex data structures like arrays and graphs through libraries and modules.
Lets Learn List,Set ,Tuple and Dictionary
List
Lists are used to store multiple items in a single variable.
Lists are created using square brackets.
We can perform many actions on Lists.
Example:
newlist=['Git','AI','Chef']
print(newlist)
Sets
Sets are used to store multiple items in a single variable.
A set is a collection which is unordered, unchangeable*(but we can remove items and add new items), and unindexed*.
Example:
thisset = {"apple", "banana", "cherry", True, 1, 2}
print(thisset)
Note: Look at the unordered sequence
Difference between Lists and Sets
List is a collection which is ordered and changeable. Allows duplicate members.
Set is a collection which is unordered, unchangeable, and unindexed. No duplicate members.
Tuple
Tuples are used to store multiple items in a single variable.
A tuple is a collection which is ordered and unchangeable.
Tuples are written with round brackets.
newTuple = ("Kicchha", "Power", "Star")
print(newTuple)
Dictionary
Dictionaries are used to store data values in key:value pairs.
A dictionary is a collection which is ordered*, changeable and do not allow duplicates.
Dictionaries are written with curly brackets, and have keys and values.
Note:In Python V3.7, dictionaries are ordered. In Python V3.6 and earlier, dictionaries are unordered.
Example:
newDict = {
"brand": "Redmi",
"model": "Note",
"year": 2023,
"Price": "29,999"
}
print(newDict)
print(newDict["year"])
Summary
List is a collection which is ordered and changeable. Allows duplicate members.
Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
Set is a collection which is unordered, unchangeable, and unindexed. No duplicate members.
Dictionary is a collection which is ordered and changeable. No duplicate members.
Tasks of Day 14
Solution:
Hands-on See Above.
Thank you for reading my Blog. I hope you have learnt something from it! If you find this blog helpful, please like, share, and follow me for more interesting posts like this in the future.
Please navigate to my GitHub Repo: GitHub Repo Link
to check my solutions for the tasks of 90daysofdevops Challenge.