Python Learning Summary

Source: Internet
Author: User

Python Learning summary Run Python code snippet

Python comes with an interpreter running in a terminal window that tries to run a Python code snippet without having to save and run the entire program.

  • >>>print ("Hello Python interpreter!" )
    Hello Python interpreter!
Variables and simple data types in Python
    1. Variable names can contain only letters, numbers, and underscores, and cannot include spaces. The value of the variable can be modified at any time in the program, and Python will always record the latest value of the variable;
    2. String
    3. Number: In Python you can perform a plus (+) minus (-) multiplication (*) on an integer (*).
    4. Floating point number: Python with decimal numbers collectively;
    5. function str ();
    6. Comment Identifier: #, the content behind the pound sign is ignored by the Python interpreter;
      • >>>0.1+0.1
        0.2
      • >>>0.2+0.2
        0.4

List element modifications, additions, deletions
    1. Modify the list element to specify the modification name and the element's lead to be modified, and then specify the new value of the element to change;
    2. Add an element at the end of the list: Method append (); Insert element in list use method: Insert () to add a new element anywhere in the list;
    3. Delete the element using the DEL statement; remove removes the element based on the value;

*motorcycles=[' ha ', ' yam ', ' su '
Print (motorcycles)
Del Motorcycles[0]
Print (motorcycles)
[' Ha ', ' yam ', ' su ']
[' Yam ', ' su ']
Here we use Del to delete the first element "ha" in motorcycles.

If statements in Python programming

Cars = [' au ', ' bm ', ' Sub ', ' Toyo ']
For car incars:
if car = = ' BM ':
Print (Car.upper ())
Elif:
Print (Car.title ())

While Loop statement

Current_number = 1
While current_number<=5:
Print (Current_number)
Current_number + = 1

Using the break Exit statement

While True:
City=input (Prompt)
If City = = ' Quit ':
Break

Using the continue statement in a loop

The continue statement is used to adjust the remaining statements of the current loop, and then proceed to the next round of loops.

Summary:
Contact this language time is not long, understand is only some fur, Python simple by many people love, programming learning is cumulative, step by step will do better. The above code is the reference book "Python programming from Getting started to practice"

Python Learning Summary

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.