Question

In: Computer Science

1. What are the main data types in Python? Which data types are sequences? 2. What...

1. What are the main data types in Python? Which data types are sequences?

2. What are some general guidelines for naming a ‘variable’ in Python? Give at least three examples of variable names that follow these guidelines

3. Provide an example of the Python syntax to create a variable to hold the age of a building (for example,40 years old).

a. Provide the Python syntax to test whether the variable created above is more than 35, and print the test result

4. What are some of the key similarities and differences between lists and tuples in Python? Give an example, using geospatial information, of when a list would be more appropriate to use and when a tuple would be a more appropriate data type?

6. Name three methods of string objects in Python, and provide an example of each one's use.

7. Given the code below: leftovers = [‘cake’,’ice cream’] t_list = [[2.5, 1.0], ‘32’, ‘alabi’, ‘Alaska’, ‘Ohio’, ‘Armenia’, 29.05, leftovers]

a. What is the ‘data type’ of the first element in t_list?

b. What is the ‘data type’ of the second t_list element?

c. What is returned by the following code snippet? print(t_list[1])

d. What is returned by the following code snippet? print(t_list[-2])

Solutions

Expert Solution

1)Main data types in python are:-

Numbers,String,List,Dictionary,Tuples

There are 3 data types which are sequences:-

List,Tuple,Range

2) In python Variable name cannot start with number .

It should start with letter or underscore.

Variable name can contain only underscore,alphabet and numbers .

The keywords cannot be used as variables.

Example:- variable, variable9,variable_9,var_iable, _variable

3) age_building=40

a) if age_building >35 :

print(age_building)

4) Similarities in list and tuples:-

They both are sequence data types

Both are used to store multiple data at same time

Differences in ĺist and tuples:-

List is dynamic means mutable that is we can add new item or delete item

Tuples are immutable that means we cannot modify the items of tuples

Tuple is static

List is useful when we have data of dissimilar data types

Tuples are useful when we have data of similar type

6) String methods

str.join() , str.replace() , str.split()

example :-

string=" Hello Everyone"

p=( , )

p.join(string) this will show Hello, everyone

string.replace(" Hello" ,"Hi") this will display Hi everyone

string.split(( ))

This will split the string at spaces

string split(( , ))

This will split the string at comma

7)a) the 1st element[ 2.5,1.0  ] is of data type list

b) data type of second element is numbers

c) 32

d)29.05


Related Solutions

In sequences and series what is a sequence and what is a series? Mention some types of sequences?
In sequences and series what is a sequence and what is a series? Mention some types of sequences?
1. What is order paper and what is bearer paper? 2. What are the main types...
1. What is order paper and what is bearer paper? 2. What are the main types of negotiable instruments? 3. What is the law merchant? 4. Who owns a corporation? 5. Who are the promoters of a corporation? 6. What does it mean to pierce the corporate veil?
genes are made of which of the following types of sequences that code for one or...
genes are made of which of the following types of sequences that code for one or more proteins
1. What are the regulatory sequences in prokaryotes & eukaryotes for transcription? 2. What are the...
1. What are the regulatory sequences in prokaryotes & eukaryotes for transcription? 2. What are the proteins involved in transcription in prokaryotes & eukaryotes? 3. What are the modifications for transcription in prokaryotes & eukaryotes
implement the following logic in Python, use appropriate data types. Data types are represented as either...
implement the following logic in Python, use appropriate data types. Data types are represented as either numeric (num) or string. string name string address num item num quantity num price num SIZE = 6 num VALID_ITEM [SIZE] = 106, 108, 307, 405, 457, 688 num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00 num sub string foundIt = “N” string MSG_YES = “Item available” string MSG_NO = “Item not found” get name, address, item, quantity sub = 0 while...
Which of the following are arithmetic sequences, which are geometric sequences, and which are neither? (a)...
Which of the following are arithmetic sequences, which are geometric sequences, and which are neither? (a) 5, 10, 20, 40, 80, Describe the sequence and the change in it. (b) 3, 8, 13, 18, 23, 28, Describe the sequence and the change in it. (c) 1, 4, 9, 16, 25 Describe the sequence and the change in it.
1) what are the main events of mitosis ? 2) what are the main events of...
1) what are the main events of mitosis ? 2) what are the main events of meiosis? 3) whay are the main events of the cell cycle ?
1. Which is the main determinant of the consumption level? Describe the relationship. 2. What is...
1. Which is the main determinant of the consumption level? Describe the relationship. 2. What is Keynes’ ‘Fundamental psychological law’? 3. What is the marginal propensity to consume (MPC) and its formula? What is the marginal propensity to save (MPS) and its formula? 4. What is the slope of the consumption function?
How to use python to find all longest common subsequences of 2 sequences? In addition, please...
How to use python to find all longest common subsequences of 2 sequences? In addition, please also analyze the space complexity. For example, the input is "ABCBDAB" and "BDCABA", then the lcs should be "BCAB" "BDAB" and "BCBA".
1. What different types of data can be part of a machine language instruction? 2. What...
1. What different types of data can be part of a machine language instruction? 2. What are some differences between RISC and CISC computers? 3. What is the general architecture of most modern computers: VonNeumann, Harvard, or Modified Harvard? 4. What descriptors from 2 and 3 above would you use to classify today's personal computers? 5. Why is it important to know whether a machine is Big-Endian or Little Endian when converting 16-bit or 32-bit data from one type of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT