Python core programming 6-conditions and loops, python core programming

Source: Internet
Author: User
Tags iterable

Python core programming 6-conditions and loops, python core programming

1. if statement

A single if statement can use the and, or, and not operators. If-elif-else. elif is else if

If expression1:
Expr1_true_suite
Elif expression2:
Expr2_true_suite
Else:
None_of_the_above_suite


2. while statement

While expression:
Suite_to_repeat


3. for statement

For iter_var in iterable:
Suite_to_repeat


4. range () built-in functions

Range (start, end, step = 1) the default step is 1.

>>> Range (2, 19, 3)
[2, 5, 8, 11, 14, 17]

>>> Range (3, 7)
[3, 4, 5, 6]


Range () has two simple syntax formats:
Range (end)
Range (start, end)


5. break, continue, and pass statements

The break statement can end the current loop and jump to the next statement.

Pass is an empty statement.


6. iterator and iter () Functions

>>> MyTuple = (123, 'xyz', 45.67)
>>> I = iter (myTuple)
>>> I. next ()
123
>>>


7. List Parsing

[Expr for iter_var in iterable]

List parsing also provides an extended version Syntax:

[Expr for iter_var in iterable if cond_expr]

The core of this statement is the for loop, which iterates all entries of the iterable object. the expr of the front edge is applied to each member of the sequence. The final result value is the list generated by this expression. iteration variables do not need to be part of the expression.

>>> [X ** 2 for x in range (6)]
[0, 1, 4, 9, 16, 25]

>>> Seq = [11, 10, 9, 9, 10, 10, 9, 8, 23, 9, 7, 18, 12, 11, 12]

>>> [X for x in seq if x % 2]
[11, 9, 9, 9, 23, 9, 7, 11]


8


What is the focus of python learning? With the second version of python core programming, how can this book be used better?

Python is the fourth-generation programming language. It has a low entry threshold and a quick start.
At the beginning, to cultivate interest, you can write some small script examples, such as batch file processing and regular expression matching;
Other network applications can also be involved.
To be more in-depth, you need to understand object-oriented.
The core programming book is a collection of online python Forum results, more practical, you can learn from examples.
Then you can look for popular python frameworks and python open-source projects to see the source code.
But in general, python has a bottleneck in efficiency. Generally, it plays the role of script cohesion and batch processing in large systems.

How does Python core programming (version 2)

Upstairs nonsense. The second version was revised for the first version because of the upgrade of the python version. This book is suitable for beginners and detailed in the basic part.
It is recommended to install python, which can be learned and tested.
This book is intended for python2.5 and should never contain 3.1

Don't buy it. If you have a computer, just go to the next pdf.

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.