Python-lesson ONE, python lesson

Source: Internet
Author: User

Python-lesson ONE, python lesson

To be honest, the first time I came into contact with Python was when I first started working, I heard that many people are very confused about this development language and there are many application fields. But these things cannot attract me. The real reason is that the development language is very simple and suitable for 2B learning. However, the more I feel that this language is awesome (although I have learned the CLASS, I feel that IQ is not enough ). So now I have to review it again. This is annoying. By the way, you can take notes for those who have just learned Python. I believe that the notes made by my primary school graduates are easy to understand.

Many people may learn a bit about Python from Linux O & M. I believe I can't do it all now. There are two ways in front of you: O & M development and pure development. Well, we don't have to talk about it anymore, because I think it may be hard to stick to it, so we don't have to flag it here. Let's start installing X ......

By the way, the Python versions we use below are Python3x, the development platform is window, And the development tool is pycharm. Now we are about to start development. Remember that you only have one O & M developer.

First, international practice: Use the vi compiler to write a sentence in Linux:

1 print("Hello World")

Is it true that you are an amazing programmer. Here, the code is printed to print the "Hello World" sentence (here we will add that if you try to use this program on the Linux platform as a wrong script), that is to say, I wrote a Python script in the vi editor. Remember to add # To the first line #! /Usr/bin/python3 or #! /Usr/bin/env python3 remember the difference between the two. env is used to find the system environment variable, that is, the default Python3 of the system. The advantage is that, the former defines the interpreter called by Python, and the latter is more flexible ).

I. Variables

Variables also have naming rules:

1. The variable cannot start with a number.

2. A variable cannot contain spaces.

3. A variable cannot be a special character or a keyword occupied by Python.

1 # variable amount 2 name = "yanweijian" # assign the yanweijian string to the name variable 3 # store data, for future convenience, call 4 x = 5 5 y = 6 6 print (y + x) # Here, x and y can be any value you enter, then add 7 # reduce repeated code 8 name = "yanweijian" 9 name2 = "abc" 10 msg = "Hello" 11 print (msg name) 12 print (msg name2) # Here we need to skip the step of entering the name and directly call the variable.

Ii. Data Types

1 int (integer): Any number (the value range of Python2x is-2 ** 31 ~ 2 ** 31-1. In a 32-bit system, 64-bit is the power of 63, but there is no limit in Python3x) 2 long (long integer ): this is no longer in Python3x, so you should put it as a skin 3 float (floating point number): http://www.cnblogs.com/alex3714/articles/5895848.html 4 complex (plural ): this younger brother really does not know, so I will not explain it. In fact, it does not use 5 6 Boolean: True or False 1 (True) or 0 (False) 7 True is the condition is True, false indicates that the condition is 8 5 + 10> 12 (True) 9 5 + 10> 18 (False) 10 11 string: "Hello 123" contains the character

Iii. Common functions of strings

1 hobbies = girl # variable 2 msg = "yanweijian is good man" # variable 3 #0123456789 ..... (subscript is also called index) and so on 4 msg. strip () # Remove the blank space 5 msg [] # For example, we only need the "yanweijian" character. Why is it written to subscript 10 here? Isn't the subscript corresponding to n 9? You need to remember to ignore your head and tail. 6 len (msg) # length 7 msg1 = msg + "and he's hobbies" + hobbies 8 print (msg1) # composite 9 # the above method actually calls the memory several times, which will occupy resources, therefore, this method is generally not used to send 10 msg1 = "% s and he's hobbies % s" % (msg, hobbies) # format the output, and the above functions are also implemented.

 

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.