When the interviewer asks these basic Python questions, there are still 80% of them!

Source: Internet
Author: User

How can I start a session of an interactive interpreter?

Under Windows, you can start an interactive session by clicking the Start button, selecting Programs, clicking Python, and then selecting the Python Command line menu option.

Where should you enter the system command line to start a script file?

Where you enter the system command line, which is where your platform is provided as a system terminal

System prompt under Windows, xterm or terminal windows in Unix, Linux, or Mac OS x.

Four or more ways to run code that is saved in a script file.

The code in a script (actually a module) file can be run using the system command line, file mouse click, import and reload, exec built-in functions, and Idegui selection like the Idle Run→run module menu option.

Two disadvantages of running a script by clicking the file icon under Windows

A script that exits after printing causes the output file to disappear immediately before you can see the output, and your script produces an error message that is also displayed in the Output window, and closes before viewing its contents (which is also why the IDE is better for most development tasks, system commands, and idle. )

How do I run a script in idle?

By default, Python will import only one module at a time, so if you change its source code and want to run its latest version without stopping or restarting Python, you will have to reload it. It has been imported at least once before you reload a module. It is no longer a problem to summarize the running code on the system command line, either by clicking on an icon, or by using an IDE like idle, because these startup mechanisms are running the latest version of the source code each time.

List the two potential drawbacks of using idle.

In the file editing window where you want to run the file, the Run→run module menu option hangs over the window. This can run the source code of this window as a top-level script file and display its output in an interactive Pythonshell window.

What is a namespace, and what is it associated with a module file

Namespaces are the encapsulation of variables (that is, variable names). It appears in Python as an object with attributes. Each module file automatically becomes a namespace; that is, an encapsulation of the variables that correspond to the copy of the top-level file. Namespaces can avoid naming conflicts in Python programs-because each module file is a separate-play namespace, file nosebleeds explicitly import other files to use the variable names of these files.

List the names of the 4 python core data types

Data, strings, lists, dictionaries, tuples, files, and collections are generally considered to be core object (data) types. Types, none, and booleans are sometimes defined in such classifications. There are also numeric types (integers, floating-point numbers, complex numbers, fractions, and decimal numbers) and multiple string types.

Why do we call them "core" data types?

They are considered to be "core" types because they are part of a senior Python language and are always valid, and in order to create other objects, it is often necessary to call the functions of the imported modules. Most core types have specific syntax to generate their objects.

What does "immutability" mean, and what are the three core data that are considered immutable?

An object with Immutability is an object that cannot be changed after its creation. Data, strings, and tuples in Python belong to this category. Although you cannot change an immutable object, you can always create a new object by running an expression.

What is the "sequence" of what three core data are considered to be in this category?

A sequence is a collection of objects for which a position is to be heard. strings, lists, and tuples are all sequences in Python. They share common sequence operations, such as indexing, merging, and slicing, but each have their own type-specific method calls.

What does "mapping" mean, the core type of Python is mapping?

A term map that represents an object that maps keys to each other. A python dictionary is a unique type of mapping for its core data types. There should be no left-to-right position order, they support fetching data by key, and include type-specific amplification calls.

What is polymorphism and why should we care about polymorphism?

Polymorphism means that the meaning of an operator (such as +) is in the object being manipulated. This becomes one of the key ideas for using Python, not restricting the code to specific types, and making the code automatically available for multiple types.

Consider the following three clusters. Do they change the value a prints out?
1 " spam " 2 3 B = A45"shrubbery"

No, a will still print as "spam". When B is assigned to the string "shrubbery", the variable B that occurs is reset to the new string object that is pointed to. A and B initially shared the same string object "spam", but in python this variable name was never linked together. Because, setting B for another different object has no effect on a. The same thing can happen if the last statement here changes to B = + + "Shrubbery". In addition, the merge operation creates a new object as its result and assigns the value to B only. We will never overwrite a string (number or tuple) in the distance, because the string is immutable.

Consider the following three statements. Do they change the value of a?
A = ["spam"="shrubbery"

Will change the value of a, A is now printed as ["shrubbery"], technically, we have neither changed a nor changed B, we have changed the part of the object that the two variables refer to together, and the object is partially covered by variable B in the distance. Because A, like B, refers to the same object, this change also has an effect on a.

Consider the following three statements. Do they change the value of a?
A = ["spam"="shrbbery"

No, a will still print as [' spam ']. Since the slice will be copied to B money to create a copy, this time to B in situ assignment will not affect. After the second assignment, there are two different list objects with the same values (in Python, we say they are = =, but are not). The third copy statement changes the list object to B, without changing the list object that points to a.

When the interviewer asks these basic Python questions, there are still 80% of them!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.