Re-reading LPTHW-Lesson1-14, lpthw. web

Source: Internet
Author: User

Re-reading LPTHW-Lesson1-14, lpthw. web

1. For python print, you can use "Hello World" or "Hello World" or "" Hello World """

2. to print a line, you can add a comma (,) after the line, that is:

print "There is only one line",print "even it looks like two lines."

3. To print multiple lines, use three quotation marks """

print “”“This is the first lineThis is the second lineThis is the last line.”“” 

 

4. If you want to enter Chinese characters, add the following code to the first line:

#-*-Coding: UTF-8-*-print u "normal Chinese test"

5. The raw_input function prompts Chinese characters and can operate as follows:

#-*-Coding: UTF-8-*-name = raw_input (" ". decode ('utf-8 '). encode ('gbk') print "% s hello! "% Name

6. # used to indicate annotation # The part after the annotation is automatically ignored by python

7. ① 3/2 = 1 in python operations; 3.0/2 = 1.5 pay attention to floating point numbers

② <= Indicates ≤> = indicates ≥

③ % Indicates that the remainder operation can be used to determine parity

④ ** Multiplication and exponent operations

⑤ Adding spaces on both sides of the operator can improve code readability

8. Pay attention to the selection of variable names. During variable naming, underlines can be used as hypothetical spaces.

9. "=" is used to assign values. "=" is used to determine whether the left and right sides are equal.

10.% indicates the format of the formatted string. It is a reserved position for the true value. It places the variable in the corresponding position and controls the display format, for example:

print "I'm %s, I am %d year old." %("Jer",23)

The format string type is as follows:

 

% S String
% R String
% C Convert to ASCII code
% B Unsigned binary integer
% D Signed decimal number
% O Unsigned octal number
% X Unsigned hexadecimal number
% E or % E Floating Point Number, represented by scientific notation
% F Floating Point Number
% String %

11. \ indicate escape characters in Python

① Enter double quotation marks in a single quotation mark string and escape them \

Escape characters Description
\ (At the end of a row) Line feed
\\ Backslash
\' Single quotes
\" Double quotation marks
\ Ring tones
\ B Backspace)
\ E Escape
\ 000 Null
\ N Line feed
\ V Vertical Tab
\ T Horizontal Tab
\ R Enter
\ F Form feed
\ Oyy A string of 8 characters in yy format. For example, \ o12 indicates a line break.
\ Xyy The character in the decimal number yy. For example, \ x0a indicates a line break.
\ Other Other characters are output in normal format

12. For pydoc, you can view the introduction to internal function creation in the Python document.

Input in Windows: python-m pydoc raw_input # view raw_input Introduction

Input in Linux: pydoc raw_input # view raw_input function Introduction

 

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.