Python Getting Started little

Source: Internet
Author: User

First, help

The Help manual in Python, for beginners, a lot of use of aid, more to see the native notes ...

1. Use of Help

1, the command need to use double quotation marks or single quotation marks, do not use quotation marks to cause error

2. Class or function (method) does not need

3. Press Q to exit Help

In [1]: Help (print)  '<ipython-input-1-3e4738e8def3>', line 1 Help    (print)             ^syntaxerror:invalid syntaxin [2]: Help ("  print") in [3]: Help (Raw_input)

2. Example

In [5]: Help (A.count) #查询a. Use of the Count method

In [6]: Help (A.index) #查询a. Use of the Index method

In [7]: Help (A.split) #查询a. Use of the Split method

Second, the common method of string processing

1, A.isdigit () #判断a变量是否是数字

2, A.isalpha () #判断a变量是否是字母

3, A.isalnum #判断a变量是否是数字或者字母

4, A.split (":") #指定: As a delimiter (delimiter can be any character) to separate the A variable, default is blank

In [8]: a="[e-mail protected]@22"in [9]: A.split ("@" ) out[9]: ['xiaozhang'nan'  A ']

5, A.lower () #将变量a转换为小写

6, A.upper () #将变量a转换为大写

7. A.count ("I") #统计 the number of occurrences of the I letter in a variable

8, A.index ("I") #显示 the I letter in a variable sequence subscript (similar array)

In [ten]: zjc="abcdefg"in[all]: Zjc.index ("e") out[]: 4 in[print  zjcabcdefgin [print zjc[4]e

Three, indentation (indented)

  In Python, the white space at the beginning of the line is very important.

Whitespace (spaces and tabs) at the beginning of a logical line is used to determine the indentation level of logical lines, which is used to determine the grouping of statements (each set of such statements is called a block). Statements at the same level must have the same indentation.

Indent Scenarios:

1, Single tab (Tab key)-à recommended use

2, two spaces, four spaces

Iv. Constants

A fixed value that cannot be changed

Type: Number, string

1, Number:5, 1.23, 67854

There are 4 types of numbers in Python: integers, long integers, floating-point numbers, complex numbers

in [+]: a=123 in[]: Type (a) out[]: intin [+]: b=111111111122222222222333333333333  in [+]: type (b) out[]: Longin []: c=1.23 in[+]: type (c) out[]: Floatin []: d=Truein [+]: type (d) out[21]: bool

2. String: "This is a string"

A string is a sequence of characters, which is basically a group of words

1. Quotation marks: Use single quotation marks ('), use double quotation marks (")

Print ' Hello World ' Hello Worldin [print'helloworld'Hello World

Use three quotation marks ("' or" ") #一般会用在多行注释里

2. Escape character

Print " hello\tworld!! " Hello    world!! In [print r]hello\tworld!! " hello\tworld!! In [print]hello\\tworld!! " hello\tworld!!

  Attention:

1, raw function: let \ t lose the function that represents the TAB key, return to original (native) character

2, add a \ Let the back of the anti-oblique bar \ Loss of meaning

In the string, the end-of-line backslash is the continuation function.

V. variables

The value of the variable can be changed, and you can use the variable to store anything.

Naming rules for variable identifiers:

1. The first character of the identifier must be the letter in the alphabet (uppercase or lowercase) or an underscore (' _ ').

2. Other parts of the identifier name can consist of a letter (uppercase or lowercase), an underscore (' _ '), or a number (0-9).

3. Identifier names are case-sensitive, for example: MyName and myname are not an identifier.

Examples of valid identifier names: I, __my_name, name_23, and A1B2_C3.

Example of invalid identifier name: 2things, this is spaced out and my-name.

Python Getting Started little

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.