Python basic interview questions
2016-05-08 13:05
555 查看
Python Interview Questions & Answers
By Parveen Kumar223
0
Share on Facebook
Tweet on Twitter
Q: – What is Python?
Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Python combines remarkable
power with very clear syntax. It has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++. It is also usable as an extension language for applications that need a programmable interface. Finally,
Python is portable: it runs on many Unix variants, on the Mac, and on PCs under MS-DOS, Windows, Windows NT, and OS/2.
Q: – Is there a tool to help find bugs or perform static analysis?
Yes.
PyChecker is a static analysis tool that finds bugs in Python source code and warns about code complexity and style.
Q: – Are there coding standards or a style guide for Python programs?
Yes
Q: – Why are Python strings immutable?
There are several advantages.
One is performance: knowing that a string is immutable means we can allocate space for it at creation time, and the storage requirements are fixed and unchanging. This is also one of the reasons for
the distinction between tuples and lists. Another advantage is that strings in Python are considered as “elemental” as numbers. No amount of activity will change the value 8 to anything else, and in Python, no amount of activity will change the string “eight”
to anything else.
Q: – Why can’t lambda forms contain statements?
Python lambda forms cannot contain statements because Python’s syntactic framework can’t handle statements nested inside expressions. However, in Python, this is not a serious problem. Unlike lambda
forms in other languages, where they add functionality, Python lambdas are only a shorthand notation if you’re too lazy to define a function.
Q: – Why isn’t all memory freed when Python exits?
Objects referenced from the global namespaces of Python modules are not always deallocated when Python exits. This may happen if there are circular references. There are also certain bits of memory that
are allocated by the C library that are impossible to free (e.g. a tool like Purify will complain about these). Python is, however, aggressive about cleaning up memory on exit and does try to destroy every single object.
Q: – Is there an equivalent to C’s onexit() in Python?
The atexit module provides a register function that is similar to C’s on exit.
Q: – Why don’t my signal handlers work?
The most common problem is that the signal handler is declared with the wrong argument list. It is called as
handler(signum, frame)
so it should be declared with two arguments:
def handler(signum, frame):
Q: – How do I create documentation from doc strings?
The pydoc module can create HTML from the doc strings in your Python source code. An alternative for creating API documentation purely from docstrings is epydoc. Sphinx can also include docstring content.
相关文章推荐
- 简述Python中"_"的使用常识
- Python学习笔记:元组(tuple)有关内容
- Python 递归
- Python函数式编程
- 利用python yielding创建协程将异步编程同步化
- 关于Python编码问题的一些看法
- python 字典转对象
- Python语言串口的操作
- Python yield 使用浅析
- Python实例---接入笑话API+发送邮件+云主机crontab定期执行
- python(3)if中字符串的判断问题
- wxpython SizerItem的大小控制
- python re.compile(?P<name>)
- python的 os 和 shutil 模块
- ubuntu14下python导入第三方so文件的路径问题
- Vim for Python & Normal Plugins & Vundle
- python爬虫抓取51cto博客大牛的文章保存到MySQL数据库
- Python数据类型详解(三)元祖:tuple
- Python数据类型详解(二)列表
- Python数据类型详解(一)字符串