Python is a cool language because you can do a lot of things with very little code in a very short period of time. Not only that, it can also easily support multitasking, such as multi-process. Python critics sometimes say python execution is slow. This article will try to introduce 6 tips to speed up your
For learning and working needs, while installing the Python 2 and Python 3 interpreters (or Anaconda 2 and Anaconda 3) to facilitate the switch between versions, we need to install the corresponding PIP for two versions
$ sudo ap
(dictionary parameters)
M.N.
M is the minimum total width displayed, and n is the number of digits after the decimal point (if available)
Python2.6 begins with the addition of a function str.format () that formats the string, which enhances the functionality of string formatting.Python three-quote (triple quotes)Three quotation marks in Python can be used to copy complex strings:Python three quotes allow a string to spa
;>> if x == 1: File "The above error is obvious, syntax error, colon is problematic. As a beginner, you may need to be wary of some of the following symbols as they are entered
English comma
English Colon
English parentheses
Brackets in English
The symbol is not accurate, the general Python interpreter will prompt SyntaxError , encounter this error do not fear, find a way to solve the good.Error
The two most commonly used modules:Os#可以允许python调用执行系统命令, such as the shellSYS#处理与python程序本身的事情Python comes with more than 200 common modulesThe Python website collects more than 2000 modules and can basically find any features you want, including graphics and interfaces .SYS module>>>Import SYS Import Module>>>Sys.pa
previous article, we introduced the use of the Power operator (* *) to calculate the N-squared of a number. In fact, you can use a function to replace this operator, this function is the POW, the function can pass two parameters, if you want to calculate X's Y, then the POW function's 1th parameter should be x, the 2nd parameter should be Y. The POW function returns the result of the calculation. For example, the following code calculates 2 of the 6-
not annotated in the compiled binaries.In the Python language, comments are divided into single-line comments and multiline comments. A single-line comment begins with a pound sign (#), and a multiline comment is enclosed in 3 quotation marks (single or double quotes). If you use a single-line comment, everything behind the pound sign is ignored when compiling the program, and if you use multiline comments
Python learning notes (10) Python collection (3) and python learning notes
Set operation
Relationship between elements and sets
The relationship between elements and a set is to determine whether an element is a member of a set. "A" in aset
1 >>> s = set ([1, 2, 3, 4]) 2 >>>
Python's 6 basic data types--dictionariesDictionarydefinition and characteristics of dictionariesA dictionary is the only type of mapping in the Python language. definition : {key1:value1,key2:value2}
1、
键与值用冒号":"分开;
2、项与项用逗号","分开;
features :
1.key:value结构
2.key必须可hash、且必须为不可变数据类型、必须唯一(数字、字符串、元组)
3.value可存放任意多个值、可修改、可以不唯一
A pit, don't know why, just record it.1 while loop! = 0:2 // omit operation 3 print loop4 if loop = = 0:5 print (ID (loop))6 print (ID (0))Running results in Python 2.7Skip loop printing with loop not 003809311234396768Running results in Python 3
("\ t" + topping)--------------------------------------------------------------------------------------------------------------- ---You ordered a thick-crust pizza with the following toppings:MushroomsExtra cheeseA For loop on the dictionary, looping the elements of the list in the dictionary again-------------------------------------------------------------------------------Favorite_languages = {' Jen ': [' python ', ' Ruby '],' Sarah ': [' C '],' E
(len (LST)-i-2,i,-1): #If the front size is small then the swap position ifLst[n-1] >Lst[n]: lst[n-1],lst[n] = lst[n],lst[n-1] BF=TruePrint("left Bubble First%s [%s]:%s,[%s]:%s compare swap%s"% (9-n-i,n-1,lst[n],n,lst[n-1],lst))Else: Print("left bubble first%s times [%s]:%s,[%s]:%s comparison invariant%s"% (9-n-i,n-1,lst[n-1],n,lst[n],lst))if notBF: BreakPrint("\ r \ n Sort after:%s"% LST)Output Result:E:\python\algorithm>Py
The probability that the program can be completed once and run normally is very small, not more than 1%. There will always be a variety of bugs to fix. Some bugs are simple, look at the error message and know that some bugs are complicated, we need to know which variables are correct, and which values are wrong, so a full set of debug programs is required to fix the bug.Method One: Print () the variables that may be problematic to see1 defFoo (s):2n =Int (s)
This chapter is based primarily on the tutorial simplification of the Python manual (shipped with Python). Have time to view the official original document. You can also find manual when you encounter a module or function that is not clear. Built-in data Types
As with most dynamic languages, a variable in Python is a dynamic variable, so you don't need to specify
function int () in the actual program. The procedure below determines whether a person is tall enough to ride a roller coaster.Height = input ("" "int(height)if: Print ("\nyou is tall enough to ride! " Else: print ("\nyou ' ll be able to ride if you ' re a little older . ")Modulo operatorWhen working with numeric information, the modulo operator (%) is a useful tool that divides two numbers and returns the remainder:4 3 1 5
Python string concatenation of 6 ways:1. PlusFirst, people with programming experience know that many languages use a plus sign to connect two strings, and Python also uses "+" directly to connect two strings;
1
print‘Python‘+‘Tab‘
Results:
1
PythonTab
2. CommaThe second is special, use a comma to co
Reply content:Let me correct and comment.
> 1. Print is no longer a statement, but a function, such as the original print ' ABC ' is now print (' abc ')
However, python2.6+ can use the from __future__ import print_function to achieve the same functionality
> 2. In Python 3, there is no old-fashioned class, only the new class, which means no more like this class Foobar (object): Pass explicitly sub-class obj
Ython is a very cool language, because very few Python code can do a lot of things in a short time, and Python can easily support multitasking and multiprocessing.Python's critics claim that Python performance is inefficient and slow to perform, but it is not: try the following 6 tips to speed up your
corresponding to the pycodeobject and stack frame corresponding f_globals build Pyfunctionobject object, and then through Store_ The name Directive associates the Pyfunctionobject object with the function name F and stores it in the local namespace. The corresponding pycodeobject of function f can be obtained and viewed by co.co_consts[0].inch[1]: Source = open (' func.py '). Read ()inch[2]: Import Disinch[3]: CO = Dis.dis (source,' func.py ',' EXEC
communicates with the code on the client so you can handle complex transactions more clearly.Now that you know the concept of an application server, let's take a look at the 6 best Python application servers.1.DjangoDjango is a free, open-source Web application framework written in the Python language that follows the model-view-controller (MVC) architecture pat
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.