Why is it useful to store information with different data types?
I would have to say that is it useful to store information with different data types because all data is different. You can have numerical data, such as social security numbers, phone numbers to name a few. Then you could also have data like names of people, cities, countries, etc. The reason why it would be useful is that these examples I mentioned would be either numeric data (social security numbers, phone numbers) or string data (people’s names, cities). So in my opinion, storing them in different data types would make it easier for us to code that way.
When do you choose to use a list over a dictionary?
I would say that we would use a list over a dictionary when we need to use things (lists) that are in sequence.
For example:
#List in sequence
item_list = [1,2,3]
#index 0 1 2
If we were to use a dictionary, we would then need to associate values with keys and we wouldn’t need to do that with a list.
Let me know your thoughts.
Thank you,
Jorge C
PART 2
Let Douglas E directly know your thoughts about his reply in 137 Words.
Data types are used to classify one type of data in Python, as they are in all computer languages. This is significant because the data type you select will dictate what values you can assign and what you can do with them. In Python, variables can be of any data type. The data type of a variable is significant because it determines the sort of data that may be stored within it. To store numeric data, for example, you’ll need a numeric type variable.
There are five standard data types: Numeric values are stored in numbers. Integers, large integers, floating-point values, and complex numbers are all types of numbers that may be stored. Strings are used to hold a collection of characters in a logical order. You type the characters within single or double quotations to define a string. Lists store elements under a single variable name, similar to arrays in other programming languages. Each element’s index, which is essentially an address that specifies the item’s position in the list, may be used to retrieve it. A list’s elements are separated by commas and specified inside square brackets ([]). Tuples are used to store a set of elements under a single variable name, analogous to lists. They cannot, however, be modified once they have been created, unlike lists. Tuples can be thought of as read-only lists. They’re used to express fixed groups of components, such as days of the week. A tuple’s elements are declared within parenthesis and separated by commas. Dictionaries, also known as mappings, are used to store a collection of items, but they do so by key rather than relative location. The curly brackets specify the components.
List example:
# Making 2 dictionaries
#means dictionary key:word value is meaning
# numFactors dictionary key:number value:number of factors
mean={“accidial”:”Dialing someone’s Number accidentally”,”awesome”:”extremely good”}
numFactors={1:1,2:2,3:2,4:3,5:2}
#using dictionary
print(‘accidial means’,mean[‘accidial’])
print(‘number of factors of 5 is’,numFactors[5])
Let me know your thoughts,
Thank you,
Douglas E.
Last Completed Projects
| topic title | academic level | Writer | delivered |
|---|
