Python Interview Questions 3

21.How will you create a dictionary using tuples in python?
dict(d) − Creates a dictionary. d must be a sequence of (key,value) tuples.

22. How will you convert an integer to a character in python?
chr(x) − Converts an integer to a character.

23.How will you convert a single character to its integer value in python?
ord(x) − Converts a single character to its integer value.

24.How will you convert an integer to hexadecimal string in python?
hex(x) − Converts an integer to a hexadecimal string.

25.What is the purpose of // operator?
// Floor Division − The division of operands where the result is the quotient in which the digits after the decimal point are removed.

26.What is the purpose of is operator?
is − Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. x is y, here is results in 1 if id(x) equals id(y).

27.What is the purpose break statement in python?
break statement − Terminates the loop statement and transfers execution to the statement immediately following the loop.

28.What is the purpose continue statement in python?
continue statement − Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

29.What is the purpose pass statement in python?
pass statement − The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute.

30.How can you get a random number in python?
random() − returns a random float r, such that 0 is less than or equal to r and r is less than 1.

No comments:

Post a Comment