python 面试问题_Python面试问答

python 面试问题_Python面试问答_第1张图片

python 面试问题

Here are 50+ frequently asked Python interview questions and answers which will definitely help you out to crack one of the toughest interviews.

这里有50多个Python面试常见问题和答案,这些绝对可以帮助您攻克最艰难的面试之一。

1. What Programming Paradigm does Python supports?

1. Python支持什么编程范例?

Python supports both Procedural Programming approach as well as Object Oriented Programming Approach. Moreover, you can use both the approaches in a single Python program.

Python支持过程编程方法和面向对象编程方法。 此外,您可以在单个Python程序中使用这两种方法。

2. Enlist the built in datatypes that Python provides.

2.征集Python提供的内置数据类型。

The datatypes provides by Python are as follows: 1. List 2. Tuple 3. Dictionary 4. String 5. Number 6. Set

Python提供的数据类型如下: 1.列表 2.元组 3.字典 4.字符串 5.数字 6.设置

python 面试问题_Python面试问答_第2张图片

3. Enlist a difference between Tuples and Lists.

3.争取元组和列表之间的差异。

Tuples and Lists are used to store a sequence of data within them. A difference between them is that Tuples once defined cannot be altered under any circumstances whereas Lists can be altered.

元组和列表用于在其中存储一系列数据。 它们之间的区别在于,一旦定义了元组,就不能在任何情况下更改元组,而可以更改列表。

4. Enlist Popular Frameworks of Python.

4.征募Python流行框架。

Major Frameworks: Django and Pyramid

主要框架:Django和Pyramid

Minor Frameworks: Bottle and Flask 5. What is Lambda in Python specification?

次要框架:瓶和烧瓶 5. Python规范中的Lambda是什么?

It is a single expression which is an Anonymous Method often used as Inline function.

它是一个单一表达式,是一种经常用作内联函数的匿名方法。

6. Enlist the Applications of Python Programming.

6.征募Python编程的应用程序。

1. Web Application Development and Web Frameworks such as DJango and Pyramid. 2. Game Development 3. Desktop Based Applications 4. Micro Frameworks such as Bottle and Flask

1. Web应用程序开发和Web框架,例如DJango和Pyramid。 2.游戏开发 3.基于桌面的应用程序 4.微型框架,例如Bottle和Flask

7. What is the grid() method used for in Python? grid() method is the one that all the widgets in a Python GUI Program’s frame have. It’s associated with a layout manager, which lets you arrange widgets in a Frame.

7. Python中使用的grid()方法是什么? grid()方法是Python GUI程序框架中所有小部件都具有的方法。 它与布局管理器关联,该管理器使您可以在框架中排列小部件。

8. Is Python a Scripting Language or not?

8. Python是不是一种脚本语言?

Python is a General-Purpose Programming Language or rather a Multi-Purpose Programming Language. It is also a Scripting Language as it can be used to combine it into HTML Code used for Web Development.

Python是一种通用编程语言,或者说是一种多功能编程语言。 它也是一种脚本语言,因为可以将其组合为用于Web开发HTML代码。

9. Explain modes in Python Programming Environment.

9.解释Python编程环境中的模式。

Script Mode: This mode is used to compile and save Python programs which is not possible in the Interactive mode.

脚本模式:此模式用于编译和保存Python程序,而在交互模式下则无法实现。

Interactive Mode: This mode can be thought of as a scratchpad to check out codes in Python Environment.

交互模式:可以将该模式视为在Python环境中签出代码的暂存器。

In order to make it executable, we should prefer Script Mode.

为了使其可执行,我们应该首选脚本模式。

10. What is Slicing in Python?

10. Python中的切片是什么?

Slicing is a terminology hat is used to generate sliced or modified output from Lists and Tuples.

切片是一个术语帽,用于从列表和元组生成切片或修改后的输出。

11. Enlist commonly used Classes in games Module in livewires Package?

11.在livewires软件包中注册游戏中常用的类吗?

The commonly used Classes in Games Module under Livewires Package are as follows: Text Screen Sprite Message

Livewires程序包下游戏模块中的常用类如下: 文本 屏幕 Sprite 消息

12. What is the difference between Print(“Hello World”) and print(“Hello World”)?

12. Print(“ Hello World”)和print(“ Hello World”)有什么区别?

Python Programming Language is Case-Sensitive. So, Print(“Hello World”) would give an error as the syntax is not correct. However, print(“Hello World”) would work perfectly.

Python编程语言区分大小写。 因此,由于语法不正确,Print(“ Hello World”)将给出错误。 但是,print(“ Hello World ”)可以完美地工作。

13. How do you create a RadioButton Element in Python?

13.如何在Python中创建RadioButton元素?

The RadioButton Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:

Tkinter模块中提供了RadioButton类。 我们首先需要导入它,然后可以通过以下命令获取框架标签:

radiobutton1 = Radiobutton(frame1, text= “C Programming”, value=0) radiobutton1.grid()

radiobutton1 =单选按钮(frame1,文本=“ C编程”,值= 0) radiobutton1.grid()

radiobutton1 is a variable to hold the Radio Button Element and frame1 is the the name of the Frame variable onto to which we want to adjust our Radio Button. The default value of a Radio Button is 1 which means ‘Selected’. We need to set it to value=0.

radiobutton1是用于保存单选按钮元素的变量,而frame1是我们要在其上调整单选按钮的Frame变量的名称。 单选按钮的默认值为1,表示“已选择”。 我们需要将其设置为value = 0。

14. How to take input from the User in Python?

14.如何从用户那里获取Python的输入?

Python provides a built-in method to accept input from the user. It is as follows: input(“Enter the Input”) However, in order to store the input in a variable, you must write a variable name before the input() method. It can done as follows: var1=input(“Enter the input”)

Python提供了一种内置方法来接受用户的输入。 如下所示:input(“输入输入”) 但是,为了将输入存储在变量中,必须在input()方法之前编写变量名称。 可以执行以下操作:var1 = input(“输入输入”)

15. How to terminate a line of code in Python?

15.如何在Python中终止一行代码?

Python is an extremely efficient and easy to use language. You can terminate a Python line of code using a Semi-Colon. However, it is not mandatory to use a Semi-colon at the end of every line. It is up to you if you want to use it or not. 16. Enlist various Exceptions identified by Python?

Python是一种非常高效且易于使用的语言。 您可以使用分号终止Python代码行。 但是,在每一行的末尾使用分号不是强制性的。 是否使用它取决于您。 16.登记Python识别的各种异常吗?

The various exceptions identified by Python Environment are as follows: 1. IOError 2. IndexError 3. KeyError 4. NameError 5. SyntaxError 6. ValueError 7. TypeError

Python Environment识别的各种异常如下: 1. IOError 2. IndexError 3. KeyError 4. NameError 5. SyntaxError 6. ValueError 7. TypeError

17. What is namespace in Python? For every variable that is introduced in Python, there is a namespace that is associated with the place holder for that particular variable. It is a place holder where a variable can be linked to the object placed.

17. Python中的名称空间是什么? 对于Python中引入的每个变量,都有一个与该特定变量的占位符关联的名称空间。 它是一个占位符,可以将变量链接到放置的对象。

18. What is a Frame in Python GUI?

18. Python GUI中的框架是什么?

A Frame in Python can be related as a storage holder for other Graphical User Interface or GUI elements such as Label, Text Entry, Text Box, Check Button, RadioButton, etc.

Python中的框架可以作为其他图形用户界面或GUI元素(如标签,文本输入,文本框,检查按钮,单选按钮等)的存储支架。

19. How do you include comment feature in a Python program?

19.您如何在Python程序中包括注释功能?

Python Programming Environment supports good features for comment as it helps the developers to document the code without any confusion. You can write a comment in a Python program using the following command:

Python编程环境支持良好的注释功能,因为它可以帮助开发人员将代码编写成文档而不会造成任何混乱。 您可以使用以下命令在Python程序中编写注释:

Syntax: # Comment Here

语法: #在这里评论

20. What is the difference between input() method and raw_input() method?

20. input()方法和raw_input()方法有什么区别?

raw_input() method returns string values whereas input() method returns integer vaues. Input() method was used in Python 2.x versions whereas Python 3.x and later versions use raw_input() method. However, input()method has been replaced by raw_input() method in Python 3.x.

raw_input()方法返回字符串值,而input()方法返回整数值。 在Python 2.x版本中使用了Input()方法,而在Python 3.x及更高版本中使用了raw_input()方法。 但是,在Python 3.x中,input()方法已由raw_input()方法代替。

21. What is the difference between Lists and Tuples in terms of Syntax?

21.就语法而言,列表和元组之间有什么区别?

Both Lists and Tuples are used to store a sequence of data within them. However, a major difference between them is that Tuples use parantheses ( ) in its syntax whereas Lists use Brackets in its syntax [ ].

列表和元组都用于在其中存储数据序列。 但是,它们之间的主要区别在于,元组在其语法中使用parantheses(),而列表在其语法[]中使用方括号。

22. What is the difference between Text Entry element and Text Box element in Tkinter Module?

22. Tkinter模块中的Text Entry元素和Text Box元素有什么区别?

A Text Entry element is used to receive an input of only one single line whereas a Text Box provides a space to receive input for multiple lines.

文本输入元素仅用于接收单行的输入,而文本框提供用于接收多行输入的空间。

23. How do you create a Check Button Element in Python?

23.如何在Python中创建一个Check Button元素?

The CheckButton class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:

Tkinter模块中提供CheckButton类。 我们首先需要导入它,然后可以通过以下命令获取框架标签:

checkbutton1 = Checkbutton(frame1, text= “C Programming”) checkbutton1.grid()

checkbutton1 = Checkbutton(frame1,text =“ C编程”) checkbutton1.grid()

checkbutton1 is a variable to hold the Check Button Element and frame1 is the name of the Frame variable onto which we want to adjust our Check Button. It takes in a parameter named as Text which is used to display the name for the Check Button.

checkbutton1是用于保存Check Button元素的变量,而frame1是我们要在其上调整Check Button的Frame变量的名称。 它接受一个名为Text的参数,该参数用于显示Check Button的名称。

24. What is the difference between a Lambda and Def?

24. Lambda和Def之间有什么区别?

A Def is a function that can contain multiple expressions whereas a Lambda can contain only one single expression. A Def method can contain return statements whereas a Lambda cannot contain return statements. A Lambda can be used inside lists and dictionaries.

Def是可以包含多个表达式的函数,而Lambda只能包含一个表达式。 Def方法可以包含return语句,而Lambda不能包含return语句。 Lambda可以在列表和字典中使用。

25. What is a Line Continuation Character in Python?

25. Python中的行延续字符是什么?

A Line continuation character in Python is the one which lets us to continue a single line of code on the next line without changing its meaning. We can do it using a Line continuation character provided by Python which is a Backslash.

Python中的行延续字符使我们可以在下一行继续一行代码而不改变其含义。 我们可以使用Python提供的Line连续字符(反斜杠)来实现。

26. How do you define the dimensions of a window in a Python Graphics Program?

26.如何在Python图形程序中定义窗口的尺寸?

We can define the dimensions i.e., width and height of a Window in a Python GUI programming. It can be defined using the geometry() method. It takes in two parameters: width and height respectively.

我们可以在Python GUI编程中定义尺寸,即窗口的宽度和高度。 可以使用geometry()方法进行定义。 它接受两个参数:分别为width和height。

Example: geometry(“width * height”)

示例:geometry(“宽*高”)

27. Enlist the Looping constructs available in Python.

27.征集Python中可用的Looping结构。

Python provides using two looping constructs and these are For Loop and While Loop. Both of these looping constructs are same. The only difference is of the syntax that both of these use.

Python提供了两个循环构造,分别是For Loop和While Loop 。 这两个循环结构都是相同的。 唯一的区别是两者都使用了语法。

28. What is range() method in Python?

28. Python中的range()方法是什么?

Range() method is Python is used as a Looping construct. It takes in 2 mandatory parameters and 1 optional parameter.

Range()方法是将Python用作Looping构造。 它接受2个必需参数和1个可选参数。

Example: range(1,10,2)

示例:range(1,10,2)

This method prints numbers after every alternate iterations between 1 and 10. It prints 1 3 5 7 9.

此方法在1到10之间的每个交替迭代之后打印数字。它打印1 3 5 7 9。

29. Are indentations mandatory to use in Python?

29.缩进是否必须在Python中使用?

Indentations are very much important to use in Python. We normally do not use braces to indicate the scope of a function in a Python program. Indentation lets the Python Interpreter to understand the scope of a function automatically. Not using indentations properly in a Python program generates errors normally.

缩进在Python中使用非常重要。 通常,我们不使用花括号来指示Python程序中函数的范围。 缩进让Python解释器自动了解函数的范围。 在Python程序中未正确使用缩进通常会产生错误。

30. Which method is used to find out the location of the pointer in a file? The tell() method is used to return the current location or position of the read/write pointer within the file. This method doesn’t require any parameter to be passed in it.

30.使用哪种方法找出指针在文件中的位置? tell()方法用于返回文件中读/写指针的当前位置或位置。 此方法不需要在其中传递任何参数。

Syntax:

句法:

FileVariableName.tell()

FileVariableName.tell()

31. Enlist the Mutable Built-in types in Python programming environment.

31.在Python编程环境中注册Mutable Built-in类型。

The Mutable Built-in types in Python Programming Environment are as follows:

Python编程环境中的Mutable内置类型如下:

1. Sets 2. Dictionaries 3. Lists

1.集 2.词典 3.列表

32. How do you create a Text Box Element in Python?

32.如何在Python中创建文本框元素?

The Text Box Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:

Tkinter模块中提供了文本框类。 我们首先需要导入它,然后可以通过以下命令获取框架标签:

text1 = Text(frame1, width = 35, height = 5) text1.grid()

text1 =文本(frame1,宽度= 35,高度= 5) text1.grid()

text1 is a variable to hold the Text Element and frame1 is the the name of the Frame variable onto to which we want to adjust our Text Box. It has two parameters viz., width and height that defines its dimensions. It is mandatory to define the Frame first.

text1是用于保存文本元素的变量,而frame1是我们要在其上调整文本框的Frame变量的名称。 它具有两个参数,即定义其尺寸的宽度和高度。 必须首先定义框架。

33. Enlist some of GUI Elements in Python Tkinter module?

33.是否在Python Tkinter模块中加入一些GUI元素?

Frame, Label, Text Entry, Check Button, Radio Button, Text Box are some of the few Tkinter GUI Elements used in Python.

框架,标签,文本输入,选中按钮,单选按钮,文本框是Python中使用的少数Tkinter GUI元素中的一些。

34. Which method is used to set the file pointer at a particular location?

34.使用哪种方法在特定位置设置文件指针?

The seek() method is used to set the File pointer to a particular position in the Text File. It takes in two parameters out of which the first one is mandatory and the second one is optional.

seek()方法用于将文件指针设置为文本文件中的特定位置。 它带有两个参数,其中第一个是必选参数,第二个是可选参数。

Syntax:

句法:

seek(location, source)

搜寻(位置,来源)

35. Why is Finally Block used in Python Exception Handling?

35.为什么在Python异常处理中使用了Final Block?

A Finally Block is generally used in association with try and catch blocks in Python. A Finally Block executes itself no matter if an error occurs at run time or not. It is the default execution block in Python Exception Handling technique.

在Python中,finally块通常与try和catch块结合使用。 无论运行时是否发生错误,Finally块都会自行执行。 它是Python异常处理技术中的默认执行块。

36. What is a DocString and what is it used for?

36.什么是DocString?它的作用是什么?

A DocString represents Document String that is used to Document Python Modules, Classes and Methods.

DocString表示用于文档Python模块,类和方法的文档字符串。

37. How is the memory management process in Python?

37. Python中的内存管理过程如何?

Like other programming environments, Python Programming Environment has Garbage Collection Techniques that manages the Memory efficiently. Moreover, the memory is managed by the Private Heap which is ultimately managed by the Python Memory Manager. 38. What is another method for Using Loops with While Loop and For Loop?

与其他编程环境一样,Python编程环境具有垃圾收集技术,可有效管理内存。 此外,内存由私有堆管理,而私有堆最终由Python内存管理器管理。 38.通过While循环和For循环使用循环的另一种方法是什么?

Python provides a method named as range() that provides looping constructs. It works in similar fashion as while and for loop. It takes in 2 compulsory parameters and 1 optional parameter.

Python提供了一个名为range()的方法,该方法提供了循环结构。 它的工作方式与while和for循环类似。 它接受2个强制参数和1个可选参数。

39. How can we import different packages in a Python program?

39.如何在Python程序中导入不同的包?

Syntax:

句法:

from Package_Name import Module_Name

从Package_Name导入Module_Name

Example:

例:

from livewires import games 40. Does Python Compiled Code contains Byte-Codes?

从livewires导入游戏 40. Python编译代码是否包含字节码?

No. Python is primarily an Interpreted Language. However, at first the .py file is compiled to something called as Python Byte-Code which is not a file that contains Binary digits like other Programming environments. It actually contains Python specific instructions that helps in optimizing the startup speed.

否。Python主要是一种解释语言。 但是,起初,.py文件被编译为称为Python字节码的文件,该文件不是像其他编程环境一样包含二进制数字的文件。 它实际上包含特定于Python的指令,可帮助优化启动速度。

41. Does Python Supports Switch Case statements?

41. Python是否支持Switch Case语句?

No, Python does not have provision for Switch Case statements. However, it provides with an alternative called as ‘One-to-One Mapping’.

不,Python没有提供Switch Case语句。 但是,它提供了一种称为“一对一映射”的替代方法。

42. How do you create a Button Element in Python?

42.如何在Python中创建一个Button元素?

The Button Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:

Tkinter模块中提供了按钮类。 我们首先需要导入它,然后可以通过以下命令获取框架标签:

button1 = Button(frame1, text = “I am a Button”) button1.grid()

button1 = Button(frame1,文本=“我是一个按钮”) button1.grid()

button1 is a variable to hold the Button Element and frame1 is the name of the Frame variable onto to which we want to adjust our Button. It is mandatory to define the Frame first.

button1是用于保存Button元素的变量,而frame1是我们要在其上调整Button的Frame变量的名称。 必须首先定义框架。

43. How do you print the sum of digits from 1 to 50 in Python?

43.如何在Python中打印1到50的数字总和?

print(sum(range(1,51))

打印(求和(范围(1,51))

This command would print in the sum of digits from 1 to 50.

此命令将以从1到50的数字总和打印。

44. What is PEP 8 in Python?

44. Python中的PEP 8是什么?

PEP 8 is a set of recommendations about writing Python Code so as to make it readable and useful for other programmers. It is more of a coding convention. 45. What is a Decorator in Python?

PEP 8是一组有关编写Python代码的建议,以使其对其他程序员具有可读性和实用性。 它更多是一种编码约定。 45.什么是Python中的装饰器?

Decorators allow you to wrap a method or a class function that executes a set of code lines before or after the execution of the original code. Decorator also allows to inject or modify code in methods or classes.

装饰器使您可以包装在执行原始代码之前或之后执行一组代码行的方法或类函数。 装饰器还允许在方法或类中注入或修改代码。

46. What is Django Framework in Python?

46.什么是Python中的Django框架?

Django is a high-level Python framweork which is used primarily for Web Development. This framework encourages fast and efficient development with pragmatic and clean design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Django是高级Python framweork,主要用于Web开发。 该框架鼓励通过实用,简洁的设计进行快速有效的开发。 它由经验丰富的开发人员构建,它解决了Web开发的大部分麻烦,因此您可以专注于编写应用程序而无需重新发明轮子。 它是免费和开源的。

47. Is Python a Compiled or an Interpreted Programming Language?

47. Python是编译语言还是解释性编程语言?

Python programs have the extension .py. These source files are first compiled to Byte Codes (which does not contain the binary codes). These Byte Code files helps in startup speed optimization. These byte-codes are then sent to the Python Virtual Machine where lines of codes are read one after another which means that it is interpreted.

Python程序的扩展名为.py。 这些源文件首先被编译为字节码(不包含二进制代码)。 这些字节代码文件有助于优化启动速度。 然后将这些字节代码发送到Python虚拟机,在Python虚拟机中逐行读取一行代码,这意味着对它进行了解释。

48. Enlist the Non-Mutable Built-in types in Python programming environment.

48.在Python编程环境中注册非可变内置类型。

The Non-Mutable Built-in types in Python Programming Environment are as follows:

Python编程环境中的非可变内置类型如下:

1. Tuples 2. Numbers 3. Strings

1.元组 2.数字 3.字符串

49. How can we define Scope in a Python program?

49.我们如何在Python程序中定义范围?

Python programming environment does not support the use of Braces for Defining Scope for a variable or a method. However, it uses Indentations to let the Python interpreter decide the scope itself. Proper indentations, if not used will normally generate an error.

Python编程环境不支持使用大括号定义变量或方法的作用域。 但是,它使用缩进让Python解释器确定范围本身。 正确的缩进(如果不使用)通常会产生错误。

50. What is Tkinter in Python and what is it used for?

50. Python中的Tkinter是什么,它的用途是什么?

Tkinter is a Python module available for Python programmers for development of Graphical User Interface (GUI) programs. Tkinter module is used to import the methods required for creation of GUI in a Python program. 51. How are exceptions handled in Python?

Tkinter是一个Python模块,可供Python程序员用于开发图形用户界面(GUI)程序。 Tkinter模块用于导入在Python程序中创建GUI所需的方法。 51.如何用Python处理异常?

An Exception is raised by Python when an error occurs at program run-time. Python Exceptions can be caught using try and catch blocks. When you are suspicious of a statement, move it it into the try block and on error the control moves into the catch block and a pre-defined activity can be executed which helps to avoid an abnormal termination of the program. 52. How do you create a Label Element in Python?

当程序运行时发生错误时,Python会引发异常。 可以使用try和catch块捕获Python异常。 当您怀疑一条语句时,将其移至try块中,并在出错时将控件移至catch块中,并可以执行预定义的活动,这有助于避免程序异常终止。 52.如何在Python中创建标签元素?

The Label Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:

标签类别在Tkinter模块中可用。 我们首先需要导入它,然后可以通过以下命令获取框架标签:

label1 = Label(frame1, text = “Here is a label!”) label1.grid()

label1 =标签(frame1,文本=“这里是标签!”) label1.grid()

label1 is a variable to hold the Label Element and frame1 is the name of the Frame variable onto to which we want to adjust our Label. So this was the list of some important Python interview questions and answers that are very frequently asked in the interviews. If you found any information incorrect or missing in above list then please mention it by commenting below.

label1是用于保存Label元素的变量,而frame1是我们要在其上调整Label的Frame变量的名称。 因此,这是一些在访谈中经常问到的重要的Python访谈问题和答案。 如果您在上面的列表中发现任何不正确或缺失的信息,请在下面的评论中提及。

翻译自: https://www.thecrazyprogrammer.com/2015/08/python-interview-questions-and-answers.html

python 面试问题

你可能感兴趣的:(列表,编程语言,python,java,linux)