Python Learning Notes

Source: Internet
Author: User

1. Compile python: Download the. tgz file, unzip the file, and perform the following operations for Python compilation:./configure; make; do install;

2. The python script extension is. py; The full path of the Python interpreter is written on the first line of the script; #!/usr/local/bin/python;#!/usr/bin/python;#!/usr/bin/env python;#!/ Bin/env python;

3. Python prompt: main prompt (>>>), secondary prompt (...) The main prompt is the interpreter telling you that it is waiting for you to enter the next statement, and the second prompt tells you that the interpreter is waiting for you to enter the rest of the current statement;

4, Python has two main ways to complete your requirements: statements and expressions (functions, arithmetic expressions, etc.);

Example:

We assign a string to the variable myString, first using print to display the contents of the variable, followed by the variable name.

>>> myString = ' Hello world! '
>>> Print myString
Hello world!
>>> myString
' Hello world! '

Note: When using only variable names, the output string is enclosed in single quotes. This is so that a non-string object can also be displayed on the screen as a string-that is, it shows the string representation of the object, not just the string itself. The quotation marks indicate that the value of the variable you just entered is a string.

5.

>>>print"%s is number%d! " % ("Python", 1)    is number 1!

Python's print statement, in conjunction with the string format operator (%), implements the string substitution function, the%s representation is replaced by a string, and%d is replaced by an integer, and the other is%f, which represents a floating-point number to replace.

6. Built-in function raw_input ()

>>> user = Raw_input (")  Enter login name:rootprint'  Your login is:', user  is: root

>>> num = raw_input (' Now enter a number: ')
Now enter a number:1024
>>> print ' Doubling your number:%d '% (int (num) * 2)
Doubling your number:2048

7, in the process of learning Python, if you need to get a strange function to help, only need to call the built-in function helper (). By using the function name as the Help () parameter, you can get the appropriate information:

>>> help (raw_input) to built-in__builtin__-string

8. Operators

>>> 2 < 3  True;      >>> 2 = = 4   False;     >>> 2 > 4   False; >>> 6.2 <= 6  False;   >>> 6.2 <= 6.2  true>>> 6.2 <= 6.20001  true;   and 2 = = 4  False; or 2 < 4  True;     not 6.2 <= 6    true>>> 3 < 4 < 5  true

9, Python variable name is case-sensitive

Python Learning Notes

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.