python tutorial - Python programming questions and answers pdf - learn python - python programming
python interview questions :191
Error thrown even if a line is commented ?
- You want to add the following line at the top of your source file:
- This tells python what is the encoding of your source file.
Learn python - python tutorial - python error line - python examples - python programs
- Source: Working with utf-8 encoding in Python source
python interview questions :192
What is a global statement in python ?
The purpose of the global statement is to declare that a function or method intends to change the value of a name from the global scope, that is, a name from outside the function.
Learn python - python tutorial - python global - python examples - python programs
python interview questions :193
What is a lazy property ?
- It is a property decorator that gets out of the way after the first call. It allows you to auto-cache a computed value.
- The standard library @property decorator is a data descriptor object and is always called, even if there is an attribute on the instance of the same name.
Learn python - python tutorial - python models - python examples - python programs
- The @cached_property decorator only has a __get__ method, which means that it is not called if there is an attribute with the same name already present. It makes use of this by setting an attribute with the same name on the instance on the first call. Given a @cached_property-decorated bar method on an instance named foo, this is what happens:
- Python resolves foo.bar. No bar attribute is found on the instance.
- Python finds the bar descriptor on the class, and calls __get__ on that.
- The cached_property __get__ method calls the decorated bar method.
python interview questions :194
On Windows, what's the difference between the various Scripts folders ?
- On a Windows installation of Python, what is the difference among the following.
- "PythonInstallFolder"\Scripts\
- %APPDATA%\Python\Scripts\
- %APPDATA%\Python\Python36\Scripts\
Learn python - python tutorial - python scripting - python examples - python programs
- I have multiple versions of python installed.
- Python27 -> C:\Users\nahawk\Python\Python27\
- Python36 -> C:\Users\nahawk\Python\Python36\
Output
python interview questions :195
What is the `is` function in Python ?
- is checks if the objects have the same identity. == only checks if they are equal.
python interview questions :196
convert a number enclosed in parentheses (string) to a negative integer (or float) using Python ?
- Assuming just removing the , is safe enough, and you may wish to apply the same function to values that may contain negative numbers or not, then:
- You could then couple that with using locale as other answers have shown, eg:
python interview questions :197
Creating a game in python ?
- How to use the while loop and accepting input within the loop.
Learn python - python tutorial - python game - python examples - python programs
Sample Code :
python interview questions :198
only() method in Python ?
- There is no only built-in function, as you'll see if you type help(only) into your Python interpreter.
- It must be pulled into the namespace with a from <module> import <only|*> instruction in that module. When you find this, you could try importing the module in your Python interpreter and using the help function again to find out what it does.
python interview questions :199
Database Cursor ?
- Probably it is most like a file handle.
- That does not mean that it is a file handle, and a cursor is actually an object - an instance of a Cursor class (depending on the actual db driver in use).
Learn python - python tutorial - python-database - python examples - python programs
- The reason that it's similar to a file handle is that you can consume data from it, but (in general) you can't go back to previously consumed data. Consumption of data is therefore unidirectional. Reading from a file handle returns characters/bytes, reading from a cursor returns rows.
python interview questions :200
Create a list in python but how to iterate through this list in javascript ?
- Add dataType:json to $.ajax script
- If you don't want to add data type then you can use jQuery.parseJSON(b) to parse your json string,