List Down Some Of The PDB Commands For Debugging Python Programs?
Here are a few PDB commands to start debugging Python code.
Add breakpoint – <b>
Resume execution – <c>
Step by step debugging – <s>
Move to next line – <n>
List source code – <l>
Print an expression – <p>
What is the difference between tuples and lists in Python?
The main differences between lists and tuples are − Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists.
What is the output of print tuple if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print complete tuple. Output would be (‘abcd’, 786, 2.23, ‘john’, 70.200000000000003).
What is the output of print tuple[0] if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print first element of the tuple. Output would be abcd.
Name some of the features of Python.
Following are some of the salient features of python
It supports functional and structured programming methods as well as OOP.
It can be used as a scripting language or can be compiled to byte-code for building large applications.
It provides very high-level dynamic data types and supports dynamic type checking.
It supports automatic garbage collection.
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Do you have any personal projects?
Really?
This shows that you are willing to do more than the bare minimum in terms of keeping your skillset up to date. If you work on personal projects and code outside of the workplace then employers are more likely to see you as an asset that will grow. Even if they don’t ask this question I find it’s useful to broach the subject.
What is the output of print str[2:5] if str = ‘Hello World!’?
It will print characters starting from 3rd to 5th. Output would be llo.
What is the output of print str[2:] if str = ‘Hello World!’?
It will print characters starting from 3rd character. Output would be llo World!.
What is the output of print str * 2 if str = ‘Hello World!’?
It will print string two times. Output would be Hello World!Hello World!.
Here are a few PDB commands to start debugging Python code.
Add breakpoint – <b>
Resume execution – <c>
Step by step debugging – <s>
Move to next line – <n>
List source code – <l>
Print an expression – <p>
What is the difference between tuples and lists in Python?
The main differences between lists and tuples are − Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists.
What is the output of print tuple if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print complete tuple. Output would be (‘abcd’, 786, 2.23, ‘john’, 70.200000000000003).
What is the output of print tuple[0] if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print first element of the tuple. Output would be abcd.
Name some of the features of Python.
Following are some of the salient features of python
It supports functional and structured programming methods as well as OOP.
It can be used as a scripting language or can be compiled to byte-code for building large applications.
It provides very high-level dynamic data types and supports dynamic type checking.
It supports automatic garbage collection.
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Do you have any personal projects?
Really?
This shows that you are willing to do more than the bare minimum in terms of keeping your skillset up to date. If you work on personal projects and code outside of the workplace then employers are more likely to see you as an asset that will grow. Even if they don’t ask this question I find it’s useful to broach the subject.
What is the output of print str[2:5] if str = ‘Hello World!’?
It will print characters starting from 3rd to 5th. Output would be llo.
What is the output of print str[2:] if str = ‘Hello World!’?
It will print characters starting from 3rd character. Output would be llo World!.
What is the output of print str * 2 if str = ‘Hello World!’?
It will print string two times. Output would be Hello World!Hello World!.
How will you convert an integer to a character in python?
chr(x) − Converts an integer to a character.
How will you convert an integer to an unicode character in python?
unichr(x) − Converts an integer to a Unicode character.
How will you convert a single character to its integer value in python?
ord(x) − Converts a single character to its integer value.
How will you convert an integer to hexadecimal string in python?
hex(x) − Converts an integer to a hexadecimal string.
How will you convert a string to all uppercase?
upper() − Converts all lowercase letters in string to uppercase.
How will you check in a string that all characters are decimal?
isdecimal() − Returns true if a unicode string contains only decimal characters and false otherwise.
What is __init__.py used for?
It declares that the given directory is a package. #Python Docs (From Endophage‘s comment).
How the string does get converted to a number?
- To convert the string into a number the built-in functions are used like int() constructor. It is a data type that is used like int (‘1’) ==1.
- float() is also used to show the number in the format as float(‘1’)=1.
- The number by default are interpreted as decimal and if it is represented by int(‘0x1’) then it gives an error as ValueError. In this the int(string,base) function takes the parameter to convert string to number in this the process will be like int(‘0x1’,16)==16. If the base parameter is defined as 0 then it is indicated by an octal and 0x indicates it as hexadecimal number.
- There is function eval() that can be used to convert string into number but it is a bit slower and present many security risks like __import__('os').system("rm -rf$HOME") - use of this will delete the home directory of the system.
What is the function of negative index?
The sequences in python are indexed and it consists of the positive as well as negative numbers. The numbers that are positive uses ‘0’ as first index and ‘1’ as the second index and the process goes on like that. The index for the negative number starts from ‘-1’ that represents the last index in the sequence and ‘-2’ as the penultimate index and the sequence carries forward like the positive number. The negative index is used to remove any new-line spaces from the string and allow the string to except the last character that is given as S[:-1]. The negative index is also used to show the index to represent the string in correct order.
chr(x) − Converts an integer to a character.
How will you convert an integer to an unicode character in python?
unichr(x) − Converts an integer to a Unicode character.
How will you convert a single character to its integer value in python?
ord(x) − Converts a single character to its integer value.
How will you convert an integer to hexadecimal string in python?
hex(x) − Converts an integer to a hexadecimal string.
How will you convert a string to all uppercase?
upper() − Converts all lowercase letters in string to uppercase.
How will you check in a string that all characters are decimal?
isdecimal() − Returns true if a unicode string contains only decimal characters and false otherwise.
What is __init__.py used for?
It declares that the given directory is a package. #Python Docs (From Endophage‘s comment).
How the string does get converted to a number?
- To convert the string into a number the built-in functions are used like int() constructor. It is a data type that is used like int (‘1’) ==1.
- float() is also used to show the number in the format as float(‘1’)=1.
- The number by default are interpreted as decimal and if it is represented by int(‘0x1’) then it gives an error as ValueError. In this the int(string,base) function takes the parameter to convert string to number in this the process will be like int(‘0x1’,16)==16. If the base parameter is defined as 0 then it is indicated by an octal and 0x indicates it as hexadecimal number.
- There is function eval() that can be used to convert string into number but it is a bit slower and present many security risks like __import__('os').system("rm -rf$HOME") - use of this will delete the home directory of the system.
What is the function of negative index?
The sequences in python are indexed and it consists of the positive as well as negative numbers. The numbers that are positive uses ‘0’ as first index and ‘1’ as the second index and the process goes on like that. The index for the negative number starts from ‘-1’ that represents the last index in the sequence and ‘-2’ as the penultimate index and the sequence carries forward like the positive number. The negative index is used to remove any new-line spaces from the string and allow the string to except the last character that is given as S[:-1]. The negative index is also used to show the index to represent the string in correct order.
Post a Comment