Python notes (1) About us should not continue to learn Python

Source: Internet
Author: User
Before the interview will be asked, Linux is not ripe? For this question: I always answer awkwardly, "well." Understand a little. "

However, when I graduated from college, I didn't even install a Linux virtual machine, let alone the system is familiar. Although I know a little bit about it, this system can be operated entirely by command. Later work, sometimes write some code, SVN submitted up, the server is Linux, and it is also running on the Windows client. Remember there is a project that asks the shell to start the Java program, do you know how I did it then? Bring their shells, ask which places to change, and then change the path to start the Java class. OK, not at all to understand the meaning inside. At the end of another interview, I had to confess that I didn't know much about Linux commands.

One might say that Linux commands are not difficult. It will take a few days to get better. Now I would like to say this with a friend who does not know Linux at all. But if I don't take the first step of learning the order. I've had to embarrass myself in the interview for a long time in the future.
Back to the point, whether we should go to study now seems useless and really good things?
My answer is: If you are a force and willing to invest in yourself, I think it is necessary.
1, this extra study will make your weekend a full-grown one.
2, when learning to a certain extent, will have a new view of things.
3, when the interview, you have a piece of chips.
4, there is a theory: the more you learn, the more you know you don't know. (The more knowledge you have, the greater the world you will see!) )

As the Love Song sings: "We have always forgotten to a bridge, to each other's heart to see", I think we have also forgotten to go to a bridge, go to another place to have a look! Oh

So let's go into the Python world together!

Python notes (1)

About Python, if you want to learn, it is recommended that you look at the site: (because I have just decided to collect a bit of time to learn it, the recommendation may not be the best)

Http://book.huihoo.com/dive-into-python/5.4_zh-cn/html/toc/index.html "Dive to Python"
http://docs.python.org/
http://woodpecker.org.cn/
Http://code.google.com/intl/zh-CN/edu/languages/google-python-class/introduction.html

I think it's great to just touch python, because if you install a software, you'll get a helloworld!.
Maybe we're old enough to be excited, in fact, I'm saying that Python is definitely the language that makes it easy for you to learn.

1, function declaration with Def

Copy CodeThe code is as follows:


def buildconnectionstring (params):



2, Import module: Import

Copy CodeThe code is as follows:


Import Odbchelper



When importing a module, the Python compiler goes to its own environment variable path to find the module, if the module to be imported is a custom path, you must put the path into the environment variables.
Copy CodeThe code is as follows:


Import Sys
Sys.path.append ('/my/new/path ')


3,if_else Statements: (Python replaces "{}" in Java by indenting control blocks of code)
Copy CodeThe code is as follows:


If n > 1:
return n * FIB (n-1)
Else
print ' End of the line '
Return 1


4, built-in data type list:
List li = ["A", "B", "Mpilgrim", "Z", "example"]

Wrap it up with "[]".

A. With the for Var in list, you can traverse a list. Do not try to add and remove elements while traversing!
Copy CodeThe code is as follows:


squares = [1, 4, 9, 16]
sum = 0
For num in Squares:
sum + = num
Print Sum # # 30


B. Use in to determine whether an element is in the list:
Copy CodeThe code is as follows:


list = [' Larry ', ' Curly ', ' Moe ']
If ' Curly ' in list:
print ' Yay


C.list Other methods:
Copy CodeThe code is as follows:


List.append (Elem)--Adds a single element to the end of the list. Common Error:does not return the new list, just modifies the original.
List.insert (Index, Elem)--Inserts the element at the given index, shifting elements to the right.
List.extend (LIST2) adds the elements in List2 to the end of the list. Using + or + = On a list are similar to using extend ().
List.index (elem)--searches for the given element from the start of the list and returns its index. Throws a ValueError If the element does not appear (use ' in ' to check without a valueerror).
List.remove (elem)--searches for the first instance of the given element and removes it (throws valueerror if not present )
List.sort ()-Sorts the list (does not return it). (The sorted () function shown below is preferred.)
List.reverse ()--Reverses the list in place (does not return it)
List.pop (Index)--removes and returns the element at the given index. Returns the rightmost element if index is omitted (roughly the opposite of append ()).


D. Other examples of list:
Copy CodeThe code is as follows:


list = [' Larry ', ' Curly ', ' Moe ']
List.append (' Shemp ') # # append Elem at end
List.insert (0, ' xxx ') # # # Insert Elem at index 0
List.extend ([' yyy ', ' zzz ']) # # Add list of Elems at end
Print List # # # [' xxx ', ' Larry ', ' Curly ', ' moe ', ' Shemp ', ' yyy ', ' zzz ']
Print List.index (' Curly ') # # 2

List.remove (' Curly ') # # Search and remove that element
List.pop (1) # # Removes and returns ' Larry '
Print List # # [' xxx ', ' moe ', ' Shemp ', ' yyy ', ' zzz ']


The sheer purpose of this article is to allow more people to learn what they may refuse to learn on various pretexts.
I hope you can be my encouragement, and some action Oh!
  • 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.