Python is very fire, the heart is very panic, have not eaten pork, also want to see pig walk.
Read the Python grammar for a few days, probably a little bit of a preliminary understanding, https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000
To combine the Python syntax, start with the simplest bubble sort.
Given the flexibility of python, even without the need for a class, you don't need the main method, just write a method and execute the method to run it.
Here's a simple attempt to encapsulate a most simple method from the class's point of view, and use the main function to specify the invocation
#Custom Test ClassesclassMytestclass:def __init__(self,s): Self.s=sdefBubble_sort (self,s):#For i in range (len (s)): forIinchRange (0,len (s)):#For J in Range (Len (s)): forJinchRange (i+1, Len (s)):ifS[i] <S[j]: Temp=S[i] S[i]=S[j] S[j]=Tempreturns#defining the Main methoddefMain ():#Test Sorts = [8, 9, 1, 3, 5, 7, 6] obj=Mytestclass (s)Print('properties of the class instance') Print(OBJ.S)Print('results before the set sort') Print(s) obj.bubble_sort (s)Print('results after the set is sorted') Print(s) forIinchRange (len (s)):Print(S[i])if __name__=='__main__': Main ()
Run results
Things hand or toss for a while, bubble sort itself has nothing to say, mainly from a grammatical point of view to Python
1,set collection, using instance: s = [8, 0, 1, 3, 5, 7, 6]
Set data, Python syntax does not need to be declared, directly use (initialize), its elements are not repeatable.
2,python The first argument of the function is self, the constructor name is fixed __init__
3,for loops through the array for I in range (len (s)), traversal, and if judgment is followed by a colon: there are some differences from the traditional programming language syntax.
Have to take part of the new learning ability, a period of time is still writing C #, and then he felt no meaning, his leader arrangements he wrote Python to do some functions, and then Wah-Hua began,
After the exchange of time found that the python has mastered the normal business with Python to achieve without pressure, can not help Alexander, himself this strongholds also eat a few days.
Remember 2010 just work that will, the department began to promote Python, cloud computing, then who is willing, the company to provide resources to learn, do not demand results, unfortunately there was no foresight, refused, now think how bloody.
Although there is no concept of these things at that time, it can be seen that the world's top 500 leaders are not eating cooked rice.
Once blew up, said, a language learned for the loop, if else after the judgment can be done, the rest is the library function mastery and skill problems, now seems to be the first blow to pay.
Reflection on the face of unfamiliar technology learning ideas, more is a way to advance, put the operation behind, I believe that the beginning is from Hello World, rather than from the Dijkstra algorithm began.
1, personally think (only the individual think) the environment is not so important, the environment of their own problems, you can help to build up, as soon as possible, as quickly as possible, or easily frustrated, the computer to play the person is not necessarily the beginning is from the back of the keyboard letter, installed system began it.
2, do not die before the concept and macroscopic things, the concept of things are behind slowly hands more to understand, in school, learned a little j2se grammar, began to die Java that set of SSH, the last job or did a C #
3, understand the simplest syntax, with their own think the most proficient in the simplest way to do, remember that year, the main function in Java string[the parameters of the meaning of the args, took a good big kung fu, the truth said at present there is no fruit.
4, think of ways to practice, although it may not be directly used in the work, with a method (language) to achieve something, try to use the newly-learned things to achieve again.
The bubble sort of sledgehammer in Python grammar test