Logo F2FInterview

Python Advanced Interview Questions

Q   |   QA

This would result in a NameError. The variable n is local to function func and can’t be accessesd outside. So, printing it won’t be possible.

n = 1
print n++ ## no such operator in python (++)

n = 1
print ++n ## no such operator in python (++)

n = 1
print n += 1 ## will work

int n = 1
print n = n+1 ##will not work as assignment can not be done in print command like this

n =1
n = n+1 ## will work

By value (check if you want to, I also did the same.  It is somewhat more complicated than I have written here (Thanks David for pointing). Explaining all here won’t be possible. Some good links that would really make you understand how things are:


Python memory management

Viewing the memory

## join without spaces the string after splitting it

s = a + ‘[' + b + ':' + c + ']‘

seems like a string is being concatenated. Nothing much can be said without knowing types of variables a, b, c. Also, if all of the a, b, c are not of type string, TypeError would be raised. This is because of the string constants (‘[' , ']‘) used in the statement.

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: