Getting Started with Python basics

Source: Internet
Author: User
Tags assert

Python Features
    • 1. Easy to learn: Python has a relatively small number of keywords, simple structure, and a well-defined syntax that is easier to learn.

    • 2. Easy to read: The Python code is defined more clearly.

    • 3. Easy maintenance: The success of Python is that its source code is fairly easy to maintain.

    • 4. A broad library of standards: One of the biggest advantages of Python is the rich library, cross-platform, compatible with Unix,windows and Macintosh very well.

    • 5. Interactive mode: interactive mode of support, you can enter the execution code from the terminal and obtain the results of the language, interactive testing and debugging code snippets.

    • 6. Portable: based on its open source features, Python has been ported (that is, making it work) to many platforms.

    • 7. Extensible: If you need a critical code that runs fast, or if you want to write some algorithms that you don't like to open, you can use C or C + + to complete that part of the program and then call it from your Python program.

    • 8. Database: Python provides the interface for all major business databases.

    • 9.GUI Programming: Python support GUI can be created and ported to many system calls.

    • 10. Embeddable: You can embed python in a C + + program to give your program's users the ability to "script".

Python Development History

Python was designed by Guido van Rossum in the late 80 and early 90 at the Dutch National Institute of Mathematics and Computer science.

Python itself is developed in many other languages, including ABC, Modula-3, C, C + +, Algol-68, SmallTalk, Unix Shell, and other scripting languages, among others.

Like the Perl language, the Python source code also follows the GPL (GNU general public License) protocol.

Now that Python is being maintained by a core development team, Guido van Rossum still occupies a vital role in guiding its progress

PythonBasic Syntax

1. First Python program

Print (' Hello python ')

Program output result: Hello Python

2.python reserved characters

The following list shows the reserved words in Python. These reserved words cannot be used as constants or variables, or as any other identifier name.

All Python keywords contain only lowercase letters.

and Exec Not
Assert Finally Or
Break For Pass
Class From Print
Continue Global Raise
Def If Return
Del Import Try
Elif Inch While
Else Is With
Except Lambda Yield

3. Line and Indent

The biggest difference between learning Python and other languages is that Python's code block does not use curly braces {} to control classes, functions, and other logical judgments. Python's most distinctive feature is the use of indentation to write modules.

The amount of whitespace indented is variable, but all code block statements must contain the same amount of indentation whitespace, which must be strictly enforced. As shown below:

4. Python Quotes

Python can use quotation marks ( ' ), double quotation marks ( " ), three quotation marks (" ' or "") to denote a string, and the beginning and end of the quotation mark must be of the same type.

Where three quotation marks can be composed of multiple lines, writing the shortcut syntax of multiple lines of text, common language file strings, at a specific location of the file, as a comment. As follows:

Print (' Hello python ') can be printed with single quotes or double quotes

Print ("Today is ' good ' Day") printed with single quotes and double quotes outside

Output: Today is ' good ' day

Print (' I'm ' like ' You ') the printed content contains double quotation marks, and a single quote will be used outside

Output: I really "like" you.

Print ("" "Today is ' Friday ', Tomorrow without" work "" "") The printed content contains both single quotation marks and double quotes, then use three quotation marks

Output: Today is ' Friday ', Tomorrow No "work"

5.python variables

The value that the variable is stored in memory. This means that there is a space in memory when creating variables.

Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.

Therefore, variables can specify different data types, which can store integers, decimals, or characters

  Variable assignments in Python do not require a type declaration, as follows:

  A = 1 #赋值整形变量

b = ' Hello ' #字符串

c = 10.99 #浮点型

6. Python conditional statements

A python conditional statement determines the code block that executes by executing the result of one or more statements (true or false).

  Python program language specifies that any non-0 and non-null (NULL) values are true

  In Python programming, if statements are used in the execution of control programs, in the basic form:

 If judging condition:
Execute statement .....
else:
EXECUTE Statement.....

7. Python Loop statement-while

Python provides a For loop and a while loop (there is no do in Python: While loop)

In Python programming, a while statement is used to loop the execution of a program, which, under certain conditions, loops through a program to handle the same tasks that require repeated processing. Its basic form is:

   While judging condition:

EXECUTE Statement .....

The execution statement can be a single statement or a block of statements. The judging condition can be any expression, and any value other than 0, or non-null (NULL), is true. The loop ends when the condition false false is judged.

Program Output Result:

 

The while statement has two other important commands, continue,break , to skip the loop, which is used to exit the loop, as follows:

The Continue is used to skip the cycle, and break is used to exit the loop, using the following:

  Dead Loop:

If the conditional judgment statement is always true, the loop will execute indefinitely, as in the following example

8. Python Loop statement-for

The For loop can traverse any sequence of items, such as a list or a string, with the following basic format:

For Iterating_var in sequence:

Statements (s)

The For loop can also use the command Continue,break to skip loops, and break is used to exit the loop, using the following:

Python Features
    • 1. Easy to learn: Python has a relatively small number of keywords, simple structure, and a well-defined syntax that is easier to learn.

    • 2. Easy to read: The Python code is defined more clearly.

    • 3. Easy maintenance: The success of Python is that its source code is fairly easy to maintain.

    • 4. A broad library of standards: One of the biggest advantages of Python is the rich library, cross-platform, compatible with Unix,windows and Macintosh very well.

    • 5. Interactive mode: interactive mode of support, you can enter the execution code from the terminal and obtain the results of the language, interactive testing and debugging code snippets.

    • 6. Portable: based on its open source features, Python has been ported (that is, making it work) to many platforms.

    • 7. Extensible: If you need a critical code that runs fast, or if you want to write some algorithms that you don't like to open, you can use C or C + + to complete that part of the program and then call it from your Python program.

    • 8. Database: Python provides the interface for all major business databases.

    • 9.GUI Programming: Python support GUI can be created and ported to many system calls.

    • 10. Embeddable: You can embed python in a C + + program to give your program's users the ability to "script".

Python Development History

Python was designed by Guido van Rossum in the late 80 and early 90 at the Dutch National Institute of Mathematics and Computer science.

Python itself is developed in many other languages, including ABC, Modula-3, C, C + +, Algol-68, SmallTalk, Unix Shell, and other scripting languages, among others.

Like the Perl language, the Python source code also follows the GPL (GNU general public License) protocol.

Now that Python is being maintained by a core development team, Guido van Rossum still occupies a vital role in guiding its progress

PythonBasic Syntax

1. First Python program

Print (' Hello python ')

Program output result: Hello Python

2.python reserved characters

The following list shows the reserved words in Python. These reserved words cannot be used as constants or variables, or as any other identifier name.

All Python keywords contain only lowercase letters.

and Exec Not
Assert Finally Or
Break For Pass
Class From Print
Continue Global Raise
Def If Return
Del Import Try
Elif Inch While
Else Is With
Except Lambda Yield

3. Line and Indent

The biggest difference between learning Python and other languages is that Python's code block does not use curly braces {} to control classes, functions, and other logical judgments. Python's most distinctive feature is the use of indentation to write modules.

The amount of whitespace indented is variable, but all code block statements must contain the same amount of indentation whitespace, which must be strictly enforced. As shown below:

4. Python Quotes

Python can use quotation marks ( ' ), double quotation marks ( " ), three quotation marks (" ' or "") to denote a string, and the beginning and end of the quotation mark must be of the same type.

Where three quotation marks can be composed of multiple lines, writing the shortcut syntax of multiple lines of text, common language file strings, at a specific location of the file, as a comment. As follows:

Print (' Hello python ') can be printed with single quotes or double quotes

Print ("Today is ' good ' Day") printed with single quotes and double quotes outside

Output: Today is ' good ' day

Print (' I'm ' like ' You ') the printed content contains double quotation marks, and a single quote will be used outside

Output: I really "like" you.

Print ("" "Today is ' Friday ', Tomorrow without" work "" "") The printed content contains both single quotation marks and double quotes, then use three quotation marks

Output: Today is ' Friday ', Tomorrow No "work"

5.python variables

The value that the variable is stored in memory. This means that there is a space in memory when creating variables.

Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.

Therefore, variables can specify different data types, which can store integers, decimals, or characters

Variable assignments in Python do not require a type declaration, as follows:

A = 1 #赋值整形变量

b = ' Hello ' #字符串

c = 10.99 #浮点型

6. Python conditional statements

A python conditional statement determines the code block that executes by executing the result of one or more statements (true or false).

  Python program language specifies that any non-0 and non-null (NULL) values are true

  In Python programming, if statements are used in the execution of control programs, in the basic form:

If judging condition:
Execute statement .....
else:
Execute statement .....

7. Python Loop statement-while

Python provides a For loop and a while loop (there is no do in Python: While loop)

In Python programming, a while statement is used to loop the execution of a program, which, under certain conditions, loops through a program to handle the same tasks that require repeated processing. Its basic form is:

While judging condition:

Execute statement .....

The execution statement can be a single statement or a block of statements. The judging condition can be any expression, and any value other than 0, or non-null (NULL), is true. The loop ends when the condition false false is judged.

Program Output Result:

 

The while statement has two other important commands, Continue,break, to skip the loop, which is used to exit the loop, as follows:

The Continue is used to skip the cycle, and break is used to exit the loop, using the following:

  Dead Loop:

If the conditional judgment statement is always true, the loop will execute indefinitely, as in the following example

8. Python Loop statement-for

The For loop can traverse any sequence of items, such as a list or a string, with the following basic format:

For Iterating_var in sequence:

Statements (s)

The For loop can also use the command Continue,break to skip loops, and break is used to exit the loop, using the following:

Python Features
    • 1. Easy to learn: Python has a relatively small number of keywords, simple structure, and a well-defined syntax that is easier to learn.

    • 2. Easy to read: The Python code is defined more clearly.

    • 3. Easy maintenance: The success of Python is that its source code is fairly easy to maintain.

    • 4. A broad library of standards: One of the biggest advantages of Python is the rich library, cross-platform, compatible with Unix,windows and Macintosh very well.

    • 5. Interactive mode: interactive mode of support, you can enter the execution code from the terminal and obtain the results of the language, interactive testing and debugging code snippets.

    • 6. Portable: based on its open source features, Python has been ported (that is, making it work) to many platforms.

    • 7. Extensible: If you need a critical code that runs fast, or if you want to write some algorithms that you don't like to open, you can use C or C + + to complete that part of the program and then call it from your Python program.

    • 8. Database: Python provides the interface for all major business databases.

    • 9.GUI Programming: Python support GUI can be created and ported to many system calls.

    • 10. Embeddable: You can embed python in a C + + program to give your program's users the ability to "script".

Python Development History

Python was designed by Guido van Rossum in the late 80 and early 90 at the Dutch National Institute of Mathematics and Computer science.

Python itself is developed in many other languages, including ABC, Modula-3, C, C + +, Algol-68, SmallTalk, Unix Shell, and other scripting languages, among others.

Like the Perl language, the Python source code also follows the GPL (GNU general public License) protocol.

Now that Python is being maintained by a core development team, Guido van Rossum still occupies a vital role in guiding its progress

PythonBasic Syntax

1. First Python program

Print (' Hello python ')

Program output result: Hello Python

2.python reserved characters

The following list shows the reserved words in Python. These reserved words cannot be used as constants or variables, or as any other identifier name.

All Python keywords contain only lowercase letters.

and Exec Not
Assert Finally Or
Break For Pass
Class From Print
Continue Global Raise
Def If Return
Del Import Try
Elif Inch While
Else Is With
Except Lambda Yield

3. Line and Indent

The biggest difference between learning Python and other languages is that Python's code block does not use curly braces {} to control classes, functions, and other logical judgments. Python's most distinctive feature is the use of indentation to write modules.

The amount of whitespace indented is variable, but all code block statements must contain the same amount of indentation whitespace, which must be strictly enforced. As shown below:

4. Python Quotes

Python can use quotation marks ( ' ), double quotation marks ( " ), three quotation marks (" ' or "") to denote a string, and the beginning and end of the quotation mark must be of the same type.

Where three quotation marks can be composed of multiple lines, writing the shortcut syntax of multiple lines of text, common language file strings, at a specific location of the file, as a comment. As follows:

Print (' Hello python ') can be printed with single quotes or double quotes

Print ("Today is ' good ' Day") printed with single quotes and double quotes outside

Output: Today is ' good ' day

Print (' I'm ' like ' You ') the printed content contains double quotation marks, and a single quote will be used outside

Output: I really "like" you.

Print ("" "Today is ' Friday ', Tomorrow without" work "" "") The printed content contains both single quotation marks and double quotes, then use three quotation marks

Output: Today is ' Friday ', Tomorrow No "work"

5.python variables

The value that the variable is stored in memory. This means that there is a space in memory when creating variables.

Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.

Therefore, variables can specify different data types, which can store integers, decimals, or characters

Variable assignments in Python do not require a type declaration, as follows:

A = 1 #赋值整形变量

b = ' Hello ' #字符串

c = 10.99 #浮点型

6. Python conditional statements

A python conditional statement determines the code block that executes by executing the result of one or more statements (true or false).

  Python program language specifies that any non-0 and non-null (NULL) values are true

  In Python programming, if statements are used in the execution of control programs, in the basic form:

If judging condition:
Execute statement .....
else:
Execute statement .....

7. Python Loop statement-while

Python provides a For loop and a while loop (there is no do in Python: While loop)

In Python programming, a while statement is used to loop the execution of a program, which, under certain conditions, loops through a program to handle the same tasks that require repeated processing. Its basic form is:

While judging condition:

Execute statement .....

The execution statement can be a single statement or a block of statements. The judging condition can be any expression, and any value other than 0, or non-null (NULL), is true. The loop ends when the condition false false is judged.

Program Output Result:

 

The while statement has two other important commands, Continue,break, to skip the loop, which is used to exit the loop, as follows:

The Continue is used to skip the cycle, and break is used to exit the loop, using the following:

  Dead Loop:

If the conditional judgment statement is always true, the loop will execute indefinitely, as in the following example

8. Python Loop statement-for

The For loop can traverse any sequence of items, such as a list or a string, with the following basic format:

For Iterating_var in sequence:

Statements (s)

The For loop can also use the command Continue,break to skip loops, and break is used to exit the loop, using the following:

  The Continue is used to skip the cycle, as follows:

Getting Started with Python basics

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.