SoFunction
Updated on 2024-11-18

python notes (1) On whether we should continue to learn python or not

In the past, when I was interviewed, I would be asked, "Are you familiar with linux? To this kind of question: I would always answer awkwardly, "Uh... I know a little bit".

However, when I graduated from college, I had never even installed a virtual machine for linux, let alone was familiar with the system. Although I understand a little bit of this system can be completely through the command to operate. Later work, sometimes write some code, svn submit up, the server is Linux, they also run the client on windows. I remember a project that required a shell to start a java program, do you know what I did at that time? I brought their shell, asked which places to change, and then changed the path to start the java class. ok, completely not to understand the meaning. At the end of another interview, I had to confess: I don't know much about Linux commands.

Some may say: there's nothing hard about Linux commands. Just take a few days and you'll be fine. That's what I would say to a friend who doesn't know Linux at all. But if I don't take the first step to learn commands. I will have to embarrass myself at interviews again for a long time to come.
Getting back to the point, should we or shouldn't we learn things that don't seem to be of much use right now but are really good?
My answer is: if you do have the spare capacity and are willing to invest in yourself, I think it's necessary.
1, this extra study will make your weekend fulfilling.
2, when learning to a certain extent, one gets a new perspective on things.
3, You have an extra piece of leverage when it comes to interviews.
4, There is a theory: the more you learn, the more you know you don't know. (The wider your knowledge, the bigger the world you see!)

As the love song goes, "We keep forgetting to get to a bridge and look inside each other's hearts," I wonder if we've forgotten to get to a bridge and look somewhere else, too! I think we've forgotten to go to a bridge and look somewhere else too!

So let's get into the PYTHON world!

python notes (1)

Regarding Python, if you're going to learn it, I recommend checking out the website: (since I've just decided to gather some bits and pieces of time to learn it, the recommendations may not be the best)

/dive-into-python/5.4_zh-cn/html/toc/《Dive to python》
/
/
/intl/zh-CN/edu/languages/google-python-class/

Being new to python I thought it was great because I could install a piece of software and immediately have a HelloWorld!
Maybe we're long past the age of excitement, and in fact, I'm trying to say that python is definitely the language to put your mind at ease and learn.

1, function declaration with def

Copy Code The code is as follows.

def buildConnectionString(params):


2, import module: import

Copy Code The code is as follows.

import odbchelper


When importing a module, the python compiler goes to the path set by its own environment variables to find the module. If the module to be imported is under a customized path, you have to put the path into the environment variables first.
Copy Code The code is as follows.

import sys
('/my/new/path')

3, if_else statements: (python controls blocks of code by indentation, instead of "{}" in java)
Copy Code The 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 with "[]".

A. Use for var in list to traverse a list. don't try to add and delete elements while traversing!
Copy Code The 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 if an element is in a list:
Copy Code The code is as follows.

list = ['larry', 'curly', 'moe']
if 'curly' in list:
print 'yay

Other methods:
Copy Code The code is as follows.

(elem) -- adds a single element to the end of the list. Common error: does not return the new list, just modifies the original.
(index, elem) -- inserts the element at the given index, shifting elements to the right.
(list2) adds the elements in list2 to the end of the list. Using + or += on a list is similar to using extend().
(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).
(elem) -- searches for the first instance of the given element and removes it (throws ValueError if not present)
() -- sorts the list in place (does not return it). (The sorted() function shown below is preferred.)
() -- reverses the list in place (does not return it)
(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 lists:
Copy Code The code is as follows.

 list = ['larry', 'curly', 'moe']
('shemp') ## append elem at end
(0, 'xxx') ## insert elem at index 0
(['yyy', 'zzz']) ## add list of elems at end
print list ## ['xxx', 'larry', 'curly', 'moe', 'shemp', 'yyy', 'zzz']
print ('curly') ## 2

('curly') ## search and remove that element
(1) ## removes and returns 'larry'
print list ## ['xxx', 'moe', 'shemp', 'yyy', 'zzz']

The pure purpose of this article is to get more people to learn what they may refuse to learn due to various excuses.
I hope you are encouraged by me me and do something about it oh!