• +91 9723535972
  • info@interviewmaterial.com

PYTHON Interview Questions and Answers

Related Subjects

PYTHON Interview Questions and Answers

Question - 31 : - What is the output of print tuple + tinytuple if tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) and tinytuple = (123, 'john')?

Answer - 31 : - It will print concatenated tuples. Output would be ('abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john').

Question - 32 : - What are Python's dictionaries?

Answer - 32 : - Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object.

Question - 33 : - How will you create a dictionary in python?

Answer - 33 : - Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([ ]). dict = {} dict['one'] = "This is one" dict[2]     = "This is two" tinydict = {'name': 'john','code':6734, 'dept': 'sales'}

Question - 34 : - How will you get all the keys from the dictionary?

Answer - 34 : - Using dictionary.keys() function, we can get all the keys from the dictionary object. print dict.keys()   # Prints all the keys.

Question - 35 : - How will you get all the values from the dictionary?

Answer - 35 : - Using dictionary.values() function, we can get all the values from the dictionary object. print dict.values()   # Prints all the values

Question - 36 : - How will you convert a string to an int in python?

Answer - 36 : - int(x [,base]) - Converts x to an integer. base specifies the base if x is a string.

Question - 37 : - How will you convert a string to a long in python?

Answer - 37 : - long(x [,base] ) - Converts x to a long integer. base specifies the base if x is a string.

Question - 38 : - How will you convert a string to a float in python?

Answer - 38 : - float(x) − Converts x to a floating-point number.

Question - 39 : - How will you convert a object to a string in python?

Answer - 39 : - str(x) − Converts object x to a string representation.

Question - 40 : - How will you convert a object to a regular expression in python?

Answer - 40 : - repr(x) − Converts object x to an expression string.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners