Some questions about Python

Source: Internet
Author: User
Tags natural string

first, what is Python?

Python (English pronunciation:/?pa?θ?n/), an object-oriented, interpreted computer programming language, was invented by Guido van Rossum at the end of 1989 and the first public release was released in 1991. The Python syntax is concise and clear, with a rich and powerful class library. It is often nicknamed the glue language, and it is easy to connect a variety of modules made in other languages. According to the different implementation methods, can be divided into: CPython (the default is implemented with C), Jython,ironpython,pypy and so on.

  1. Python is an interpreted language rather than a compiled language: converts the source code into bytecode, then interprets the bytecode and executes it.

interpreted language: The program does not need to compile, the program is translated into machine language at run time, each time to be translated once. Therefore, the efficiency is lower. In the basic language, for example, there is an interpreter that can execute the basic program directly, and each statement is translated when it is executed.
compiled language: The program needs a special compilation process before execution, the program is compiled into machine language files, the runtime does not need to re-translate, directly using the results of the compilation is OK. The program executes efficiently, relies on the compiler, the cross-platform is inferior. such as C, C + +, Delphi, etc.

compiled and interpreted type, both have pros and cons
The former because of the fast program execution, the same conditions on the system requirements are low, so like the development of operating systems, large applications, database systems, such as the use of it, such as C + +, Pascal/object Pascal (Delphi) are compiled languages, and some web scripts, Server Scripts and auxiliary development interfaces The programs that are not fast-to-speed and require compatibility with different system platforms often use explanatory languages such as JavaScript, VBScript, Perl, Python, Ruby, MATLAB, and so on.

  2. Why are there so many Python implementations?
  
As mentioned earlier, CPython is the most common, is a C implementation, is considered "default" implementation. But what about the others? One of the most prominent of these is Jython, a Java implementation that uses the JVM. It's easy to write C extensions for your Python code in CPython because the C interpreter is ultimately executed. Jython, on the other hand, makes it easy to work with other Java programs: Without additional work, you can import any Java class and use other Java classes in your Jython program. IronPython is another popular Python implementation, implemented entirely in C #, against. NET platform. She runs in what can be called. NET virtual machine, this is Microsoft's Common Language Runtime (CLR), which corresponds to the JVM.

second, why use Python?1. High development efficiency

Python is the most efficient language to develop, it is 6 times times more efficient than C, and simply, if a C developer is working for 6 days, a developer using Python will only have to work one day, meaning that a python developer can only be on the day of the week. It is twice times more efficient than C + +, and it is 1.5 times times more efficient than Java and C #. There is such a high development efficiency, of course, the cost of performance, but from the current hardware technology progress, the current CPU computing capacity is generally excessive, and more and more hardware costs are reduced, but the cost of labor more expensive. In fact, from the perspective of social progress, but also tools more and more advanced, but the complexity of the brain management is not followed by improvement, obviously to improve it is more difficult.

2. Easy commissioning and operation

Both on the Windows platform and the Linux platform, they are developed and debugged as well. Cross-platform operation is more convenient, if there is no platform differences in the API interface, just write the code once, you can run on the Windows platform or Linux platform.

3, open source free

Python, both commercially and in education, is free to use, meaning it can be entered at zero cost to learn it and use it. Python has a number of well-functioning development libraries to use.

4. Testing field Requirements

Testing is a considerable amount of work in software development, such as module testing, when the developer has completed a module function, the need to test whether the module is correct, you need to build a bunch of test code, can be verified. At this point, if you use C + + or Java to write these features, obviously not using python come quickly, from the previous efficiency can be seen. As a result, this is usually the development pattern: The published software is developed using C + + or Java, but the code tested is developed using Python. For instance, the embedded system involves the network communication aspect, needs to send the network data and receives the network data unceasingly to the embedded system, may use the Python to build a test environment, so spends the very little time, can the embedded system verification, improves the code quality, Reduce commissioning time for embedded systems and other systems, as well as later maintenance times. In addition, by using the Python language to write a large number of scripts, you can improve the level of automated testing, each release of a version, you can put the previous test cases, fully automated testing, which will greatly improve the rapid release of software requirements. Like the test cases I've seen, there are tens of thousands of of them, which, if tested by hand, are very slow and not comprehensive. The current use of fully automated testing, 24 hours a day to run, a computer equivalent to 10 test staff workload, can be seen to bring much efficiency. In the foreseeable future, in the field of testing, Python's job requirements will continue to increase, requiring all testers to master this handy tool.
 

Iii. What are the Python application areas?

Python is not just a well-designed programming language, it can accomplish a variety of tasks in the real world, including what developers do day after day. As a tool for compiling other components and implementing standalone programs, it is often used in a variety of fields. In fact, as a common language, Python's application role is almost limitless: you can apply Python on any occasion, from website and game development to robotics and Space shuttle control.
  
  Main applications include: System programming, User graphics interface, Internet scripting, component integration, database programming, rapid prototyping, numerical computing and scientific computing programming, games, graphics, artificial intelligence, XML, robotics, etc. 
  
See: http://blog.163.com/myhome_2/blog/static/28595817201311259355568/

What is the uniqueness of Python syntax? 1. Basic Concepts

A, number
There are 4 types of numbers in Python-integers, long integers, floating-point numbers, and complex numbers.
(1) 2 is an example of an integer.
(2) long integers are just larger integers.
(2) 3.23 and 52.3E-4 are examples of floating-point numbers. The e tag represents a power of 10. Here, 52.3E-4 means 52.3 * 10-4.
(4) ( -5+4j) and (2.3-4.6j) are examples of complex numbers.

B, String
(1) using single quotation marks (')
(2) Use double quotation marks (")
(3) Use three quotation marks ("' or" "")
Using the three quotes, you can indicate a multiline string. You can use single and double quotation marks freely in three quotes. For example:

‘‘‘This is a multi-line string. This is the first line.This is the second line."What‘s your name?," I asked.He said "Bond, James Bond."‘‘‘

(4) Escape character
(5) Natural string
Natural strings are specified by prefixing the string with R or R. For example R "Newlines is indicated by \ n".

C, logical lines and physical lines
Using more than one logical line in a physical row requires the use of semicolons (;) to specifically indicate this usage. A physical line can have only one logical line without semicolons

2. Data Structure

A, List

Shoplist = [' Apple ',' Mango ',' Carrot ',' Banana ']Print ' I have ', Len (shoplist),' items to purchase. 'Print ' These items are: ',# Notice The comma at end of the line forIteminchShoplist:PrintItemPrint ' \ni also has to buy rice. 'Shoplist.append (' Rice ')Print ' My shopping list is now ', shoplistPrint ' I'll sort my list now 'Shoplist.sort ()Print ' Sorted shopping list is ', shoplistPrint ' The first item I'll buy is ', shoplist[0]olditem = shoplist[0]delshoplist[0]Print ' I bought the ', OlditemPrint ' My shopping list is now ', shoplist

B, tuple
Tuples and lists are very similar, except that tuples and strings are immutable, meaning that you cannot modify tuples.

Zoo = (' Wolf‘,' Elephant‘,' Penguin') print' number  ofAnimalsinchThe zoo is', Len (zoo) New_zoo = (' Monkey‘,' Dolphin', zoo) print' number  ofAnimalsinchTheNewZoo is', Len (new_zoo) Print' AllAnimalsinch NewZoo is ', new_zooprint' AnimalsBrought from the old Zoo is ', new_zoo[2]print' lastAnimal brought from the old zoo is', new_zoo[2][2]

Like a tree
Tuples and printing

22nameis %d years old‘ % (nameiswiththatname

C, Dictionaries
Similar hashes

AB = {' Swaroop ':' [email protected] ',' Larry ':' [email protected] ',' Matsumoto ':' [email protected] ',' spammer ':' [email protected] '}Print "Swaroop's address is%s"% ab[' Swaroop ']# Adding a key/value pairab[' Guido '] =' [email protected] '# Deleting a key/value pairdelab[' spammer ']Print ' \nthere is%d contacts in the address-book\n '% Len (AB) forName, AddressinchAb.items ():Print ' contact%s at%s '% (name, address)if ' Guido ' inchAb:# OR Ab.has_key (' Guido ')  Print "\nguido's address is%s"% ab[' Guido ']

D, Sequence
Lists, tuples, and strings are sequences. The two main features of a sequence are index operators and slice operators.

Shoplist = [' Apple‘,' Mango‘,' Carrot‘,' Banana']# indexingor ' Subscription' Operationprint' Item 0  is', shoplist[0]print' Item 1  is', shoplist[1]print' Item-1  is', shoplist[-1]print' Item-2  is', shoplist[-2]# slicing onA listprint' Item 1  to 3  is', shoplist[1:3]print' Item 2  to End  is', shoplist[2:]print' Item 1  to-1  is', shoplist[1:-1]print' ItemStart to End  is', shoplist[:]# slicing onAstringName =' Swaroop' Print' characters 1  to 3  is', name[1:3]print' characters 2  to End  is', name[2:]print' characters 1  to-1  is', name[1:-1]print' charactersStart to End  is', name[:]

E, reference
When you create an object and assign a variable to it, the variable simply refers to that object, not the object itself! In other words, the variable name points to the memory of the object stored in your computer. This is called the name-to-object binding.

Print ' simple assignment 'Shoplist = [' Apple ',' Mango ',' Carrot ',' Banana ']mylist = Shoplist# mylist is just another name pointing to the same object!delshoplist[0]Print ' Shoplist is ', shoplistPrint ' MyList is ', MyList# Notice that both Shoplist and MyList both print the same list without# the ' Apple ' confirming that they point to the same objectPrint ' Copy by making a full slice 'MyList = shoplist[:]# Make a copy by doing a full slicedelmylist[0]# Remove First itemPrint ' Shoplist is ', shoplistPrint ' MyList is ', MyList# Notice that now the lists is different

F, String

Name =' Swaroop' # this isAstringObjectifName.startswith (' Swa'): Print' Yes, thestringStarts with "Swa"‘if ' a‘inchName:print' Yes, it contains thestring "a"‘ifName.find (' War')! =-1: Print' Yes, it contains thestring "war"' delimiter = ' _*_ ' mylist = [' Brazil‘,' Russia‘,' India‘,' China']print delimiter.join (mylist)//using delimiter to connect mylist characters

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Some questions about Python

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.