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 … 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> … 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, … Read more

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 … Read more

What is the usage of help() and dir() function in Python?

Help() and dir() both functions are accessible from the Python interpreter and used for viewing a consolidated dump of built-in functions. Help() function: The help() function is used to display the documentation string and also facilitates us to see the help related to modules, keywords, and attributes. Dir() function: The dir() function is used to … Read more