In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article is to share with you what the 22 practical skills of Python are, the editor thinks they are very practical, so I share them with you to learn. I hope you can get something after reading this article.
Python, which is popular with artificial intelligence, is already a well-developed and diversified language, and there must be some features that you haven't discovered yet. Then maybe I can teach you some new skills today.
Development of Python:
"Life is too short, I use Python." Python's classic slogan is racing against the clock. It took 10 years to enter the top 10 index for the first time since the early 1990s. With its continuous application and development, Python gradually shines in the fields of network security and data science.
Python was originally the successor to Perl, used to write build scripts, and as a glue language, it is widely used to connect various software components. However, with the continuous application and development, Python has gradually entered other fields, such as network security and data science. Nowadays, it is very common to run Python in large embedded systems, and with the popularity of artificial intelligence and data analysis, Python has received unprecedented attention. It is believed that it will keep moving forward.
At present, it has become the preferred programming language for universities around the world, and has conquered the industrial world at the same time. More and more people are using Python, which is reflected in the TIOBE index that it has climbed steadily step by step, from 10 to 5, but now it has finally entered the top 3.
Essential skills for Python:
1. Concise expression
Comments: Python is famous for its simplicity and efficiency because of its simple syntax and built-in powerful data structures:
For example, we can use a lot of derivation lists to generate a lot of concise code.
For example, we can use if else combination, originally need 2-3 lines of code to write, one line to do!
2. Sort
Neglect to think of a line, "where there are people, there are rivers and lakes", then the data structure such as an array must involve sorting, taking the maximum value and the minimum value.
Comments: this heapq library is very easy to use, especially when we are taking the header data of some lists, such as the largest ones and the smallest ones, which are often used, a very practical move! Don't say anything, just memorize it!
3. Query
Sorting and query are good friends, and we must have the need for query and filtering in the long data structure (dictionary, list). Sometimes, we need to find a certain element or class of elements from a long list. What to do? simply, use the high-level function filter:
1)。 Filter with lambda and filter
Comments: lambda is a very concise functional expression, short and short, coupled with the use of filter, very beautiful. For example, we can easily filter out the data we need in the list through the startswith built-in function in the string! (Python3 slightly change and add a list to the filter, otherwise the iterator address will be generated.)
Comments: regularization is a very good filtering method, sometimes good regular top dozens of lines of code, proficient in regular game data analysis, data cleaning is a necessary skill!
4. Flattening list
Sometimes we will encounter complex data structures, such as the list inside the list, layer by layer nesting, very troublesome. Methods that can be flattened:
Traditional methods
Comments: this is solved by recursion, the train of thought is very simple and clear, but recursion must have an exit, we should pay attention to it when designing.
In addition, there are two master writing methods, which are more complicated to understand. Here, you can look for those who are interested.
5. Derivation list with conditions
Derivation list should be my favorite way of Pythonic, its evolution has a lot of techniques, these are very common, read it a few times, memorize it!
6. A beautiful way to add a dictionary
When designing data structures, dictionaries are necessary! Most of the time we will use the following dictionary update method, of course, better is the defaultdict in the collections module!
Comments: dict.update is relatively approachable, this dict (dict,**options) usage I saw for the first time is also froze some, what the hell, now see more, also get used to it!
Python's selected skills:
1, all or any
One of the reasons why Python is so popular is that it is readable and expressive.
People often joke that Python is "executable pseudo code", but when you can write code in this way, it's hard to refute it.
2 、 bashplotlib
Do you want to draw graphics on the console (console)?
1$ pip install bashplotlib
So you can draw graphics in the console.
3. Set
Python has built-in default data types, but sometimes they don't work as well.
Fortunately, Python's standard library provides the collections module, and this convenient additional library provides more data types.
From collections import OrderedDict, Counter
X = OrderedDict (axi1, baux2, cyste3)
Y = Counter ("Hello World!")
4 、 dir
Have you ever had the idea of going deep inside a Python object and observing what properties it has?
Enter the following command line:
This is a very useful feature when running Python interactively, and you can dynamically search for objects and modules in use.
5 、 emoji
Python contains the emoji module, here!
$pip install emoji
Don't think I didn't know you'd download it secretly.
6. Exchange two numbers in place
Python provides an intuitive way to assign and exchange values (variable values) in one line of code, as shown in the following example:
XMagna y = 10, 10, 20 print (x, 10), y, 1, (10, 20), 2, 10)
A new tuple is formed on the right side of the assignment, and the left immediately parses (unpack) that (unreferenced) tuple to the variable sum.
Once the assignment is complete, the new tuple becomes unreferenced and marked as garbage collected, and the variable exchange is finally completed.
7 、 from _ future_import
One result of the popularity of Python is that new versions are always under development. A new version means new features-unless the version is out of date
But don't worry. _ future_module allows users to import the functionality of a new version of Python through functions. It's like time travel, or strange magic.
From _ _ future__ import print_function
Print ("Hello World!")
Why not import curly braces?
8 、 geopy
Geography can be a challenging area for programmers. But the geopy module makes it extraordinarily simple.
$pip install geopy
It works by extracting a series of API from different geocoding services, allowing users to get the complete street address, latitude, longitude, and even altitude of a place.
Another useful function is distance: it can calculate the distance between two positions in your favorite unit of measurement.
9. Chain comparison operator
Aggregating comparison operators is another sometimes convenient technique:
N = 10 result1
< n< 20print(result)# Trueresult= 1>N > > 2 + 13 > _ 3 > print_3
13 、 List Comprehensions
One of my favorite things about Python programming is its list generation (List Comprehensions)
These expressions can be easily written into concise code and read almost like a natural language.
14 、 Jedi
The Jedi library is a library for automatic completion and code analysis. It can make writing code faster and more efficient.
Unless you are developing your own IDE, you may be most interested in using Jedi as an editor plug-in. Fortunately, loading this plug-in is now available! However, you may already be using Jedi. The code completion function of the IPython project is implemented using Jedi.
15 、 map
Python supports functional programming through many built-in features. The map () function is one of the most useful functions-- especially when used in conjunction with the lambda function.
In the above example, map () applies a simple lambda function to each element in x. It returns a map object that can be converted into an iterable object, such as a list or tuple.
16. * * kwargs
There are many milestones in the process of learning any language. Using Python, understanding the mysterious * * kwargs syntax may be one of them.
The double asterisk in front of the dictionary object allows you to pass the contents of the dictionary as a named argument to the function.
The key of dictionary is the parameter name, and the value is the value passed to the function. You don't even have to call it kwargs!
This is useful when you want to write functions that handle named parameters that are not predefined.
These are the 22 practical skills of Python, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.