I. Environment and BACKGROUNDWINOWS10 + python2.7 + python3.5Need to use print in python2.7 and no line breakIi. Methods of Use1. Add a comma at the endprint "Hello World",Problem: After the output of the result will be more a space , this space put me pit 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0065.gif "alt=" j_0065. GIF "/>2. Using the SYS moduleImport sys sys.stdout.write ("Hello World") Sys.stdout.flush ()3. Using the
Print (with comma) separated by commas
This allows for continuous output
Print (J, "*", I, "=", j*i,end= "") ends with end to determine the format of the next output and the middle of the output
forIinchRange1,Ten): forJinchRange1, i+1): Print (J,"*"I"=", j*i,end=" ") ifj = =I:print ("\ n")1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2
The point is,end= "" means that the next print does not wrap.Instance:1 forXinchRange (1,10):2 forYinchRange (1,10):3 ifx>=y:4 Print(X,"x"Y"=", X*y," ", end="")5 Print()Output results1 x 1 = 1 2 x 1 = 2 2 x 2 = 4 3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 4 x 1 = 4 4 x 2 = 8 4 x 4 = 5 x 1 = 5 5 x 2 = 5 x 3 = 5 x 4 = 5 x
Print output line in Python, if you want to output more than the content of the line, you can add a comma after printFor exampleOne row per output" ABCDEFG " # Add your for loop for inch phrase: Print CharAbcdefgOutput on the same linephrase ="A Bird in the hand ..."#Add your for loop forCharinchphrase:if(char = ="A" orchar = ='a'):
To intercept the string output, the following example will only output the first 3 letters of a string>>> str="ABCDEFG">>>Print "%.3s"%STR ABC is output at fixed width, insufficient space complement, the following example output width is ten>>> str="ABCDEFG">>>Print "%10s"%str ABCDEFG intercept string, output by fixed width>>> str="ABCDEFG">>>Print "%10.3s"%STR A
This article is an example of how Python prints the Scrapy spider crawl tree structure. Share to everyone for your reference. Specifically as follows:
The following code can be understood at a Glance scrapy crawl page structure, the call is very simple
#!/usr/bin/env python
import fileinput, re from
collections import defaultdict
def print_urls (Allurls, Referer, indent=0):
urls = allurls[referer] f
I. Error handling1. Use try: Exception. FinallyTry: print ' Try ... ' r = 10/0 print ' Result: ', R # exception does not print this sentence except Zerodivisionerror, E: # If there is an exception, it will be captured to the C6/>print ' except: ', Eelse: print
the Python string is formatted using the "character% format 1% format 2 characters"% (variable 1, variable 2), and the% format represents the type of the accepted variable. Simple examples of use are as follows# Example: String formattingName = ' 17jo 'print ' www.%s.com '%name>> www.111cn.netName = ' 17jo 'Zone = ' com 'print ' www.%s.%s '% (name,zone)>> www.111
landing page, enter the correct login information, will jump to the system homepage. It would be a good use case to get the URL after the jump and then determine if it matches the URL of the system's homepage.Code#!/usr/bin/env python#-*-coding:utf-8-*-"' Created on 2018/5/9 11:23@author:jeff lee@file: Title of current page and url.py ' from S Elenium Import webdriverimport timeprint (' Open browser ') CL = Webdriver. Firefox () time.sleep () url =
"python exercise 024" gives a positive integer not more than 5 digits, requires: First, it is a number of digits, second, in reverse order to print out the figures.----------------------------------------------This problem if not recursive, it is too simple!!! On the code:str = input (' Enter a positive integer not more than 5 bits: ') print (' This number is the
alignment of the string for the desired length:> Right Alignment^ Middle Alignment= (for numbers only) after the decimal point4.Python_ Escape Character
Escape character
Describe
\ (at end of line)
Line continuation character
\\
Backslash symbol
\‘
Single quotation marks
\"
Double quotes
\a
Bell
\b
BACKSPACE (Backspace)
\e
Escape
1 ImportSYS2 Import Time3total_size=102124Recv_size=05 defProgress (percent,width=50):6 ifPercent > 1:#if the percentage is greater than 1, take 1.7Percent=18Show_str= ('[%%-%ds]'%width)% (int (percent*width) *'#')9 #altogether 50 #,%d unsigned integers,-representing left-aligned, non-newline output, two% representing a pure%, corresponding to the back of S, followed by the number of control # numbersTen #print (SHOW_STR) #[###############
in the code where it is needed, as follows: 1 Import PDB 2 3 if __name__ " __main__ " : 4 A = 15 # create PDB code fragment 6 b = 27 C = A + b 8 Print (c)Enter the PDB command and view the results: 4, log, locate the problem record program operation is mainly introduced logging Library logging module provides a standard log interface, you can store various formats of the log, logging log can be divided intodebug(), info(), warning(), error()
Tags: Linux python pdbIn Linux, you can use debugging at the interface and command line, where you record command-line debugging
At the command line, use thepython27-m pdb use_infix2postfix.py to enter debug mode
>/root/py/algor/use_infix2postfix.py (7) Import types This is the first statement of the script
H (ELP)
(Pdb) HDocumented commands (Type help =================================
1. Release statementpython3.6.5django2.0.62. Open Project-settingThe debug default in setting.py is equal to true, so that if there is an error in the provider that will directly show all the configuration information of the project, then if we are deployed in a formal environment, it is too dangerousSo deploy to the formal environment, need to debug to false,allowed_hosts=[] also need to modify allowed_hos
Let me ask you a question why the print function prints parameters directly. Even the numbers? For example, print 1 prints 1. We know that the type of 1 is integer (off-topic, 1 is a constant in Python, is also an object of class int, and 1 in Java is a constant), which is supposed to be the string of the parameters that prin
The Python string is formatted with the character% format 1 format 2 character% (variable 1, variable 2), and the% format represents the type that accepts the variable. Examples of simple uses are as follows
# Example: String formattingName = ' 17jo 'print ' www.%s.com '%name>> www.111cn.net
Name = ' 17jo 'Zone = ' com 'print ' www.%s.%s '% (name,zone)>> www.11
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.