Python Interview Questions | Eklavya Online

Python Interview Questions

How can we make forms in Python?

You have to import CGI module to access form fields using FieldStorage class. Attributes of class FieldStorage for the form: form.name: The name of the field, if specified. form.filename: If an FTP transaction, the client-side filename. form.value: The value of the field as a string. form.file: file object from which data read. form.type: The content …

How can we make forms in Python? Read More »

Which are the file related libraries/modules in Python?

The Python provides libraries/modules that enable you to manipulate text files and binary files on the file system. It helps to create files, update their contents, copy, and delete files. The libraries are os, os.path, and shutil. Here, os and os.path – modules include a function for accessing the filesystem while shutil – module enables …

Which are the file related libraries/modules in Python? Read More »

What are the differences between Python 2.x and Python 3.x?

Python 2.x is an older version of Python. Python 3.x is newer and latest version. Python 2.x is legacy now. Python 3.x is the present and future of this language. The most visible difference between Python2 and Python3 is in print statement (function). In Python 2, it looks like print “Hello”, and in Python 3, …

What are the differences between Python 2.x and Python 3.x? Read More »

What are the different file processing modes supported by Python?

Python provides three modes to open files. The read-only, write-only, read-write and append mode. ‘r’ is used to open a file in read-only mode, ‘w’ is used to open a file in write-only mode, ‘rw’ is used to open in reading and write mode, ‘a’ is used to open a file in append mode. If …

What are the different file processing modes supported by Python? Read More »

How can you organize your code to make it easier to change the base class?

You have to define an alias for the base class, assign the real base class to it before your class definition, and use the alias throughout your class. You can also use this method if you want to decide dynamically (e.g., depending on availability of resources) which base class to use. Example BaseAlias = <real base class> …

How can you organize your code to make it easier to change the base class? Read More »

How Python does Compile-time and Run-time code checking?

In Python, some amount of coding is done at compile time, but most of the checking such as type, name, etc. are postponed until code execution. Consequently, if the Python code references a user-defined function that does not exist, the code will compile successfully. The Python code will fail only with an exception when the …

How Python does Compile-time and Run-time code checking? Read More »