In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the key technologies of Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what the key technologies of Python are.
01. Brief introduction to Python what is Python
An object-oriented advanced dynamic interpretable scripting language.
The Python interpreter reads one line of code at a time, interprets it as a low-level machine language, such as bytecode, and executes it.
As a result, the language often causes run errors.
Why choose Python (advantage)
Python is currently the most popular language because it is easier to code and has strong interpretability.
Python is an object-oriented programming language, which can also be used to write some functional code.
Python is a good way to bridge the gap between business and developers.
Compared with other languages such as C#/Java, Python programs have been on the market for less time.
Python comes with a large number of machine learning and analysis packages.
A number of communities and books are available to support Python developers.
Almost all types of applications, from predictive analysis to UI, can be implemented in Python.
Python programs do not need to declare variable types. As a result, the applications built can run faster.
Why not choose Python (disadvantage)
Compared to other languages, Python programs run more slowly because of the lack of support similar to the Just In Time optimizer in Python.
The blank constraint of Python syntax brings some difficulties to novice coding.
Python does not provide advanced statistical capabilities like the R language.
Python is not suitable for low-level system and hardware interaction.
How Python works
The following figure shows how Python works on the machine. The key here is the interpreter, which is responsible for compiling the high-level Python language into a low-level machine language for easy understanding.
02. Variable-target type and scope
Variables that can be used in a program store information, such as saving user input, the local state of the program, and so on.
Variables in Python are named after names.
Variable types in Python include numbers, strings, collections, lists, tuples, and dictionaries, which are standard data types.
Declare and assign a value to a variable
This is as follows: first, assign the integer value 1 and the string "Hello You" to the variable myFirstVariable. Because the data types in Python are dynamic, this repeated assignment is possible.
The variable assignment operation in Python is also called blinding.
Numerical type
As shown below, Python supports integer, decimal, and floating point data.
In addition, long integers are also supported, with L as the suffix, such as 999999999999L.
String
A string is a sequence of letters that represents text information.
The value of the string is enclosed in quotation marks, as shown below.
Strings are immutable and cannot be modified once created. As follows:
When a string variable is assigned a new value, Python creates a new target to store the variable value.
Local and global variables
Local variable
A local variable, such as declaring a variable within a function, exists only in that function.
Local variables are inaccessible externally, as shown below.
The if-else and for/while loop modules in Python cannot create local variables, as shown in the for/while loop:
The output is:
In the if-else module:
Output as
All variables
Global variables can be accessed through any global function, and they exist in the _ _ main__ framework.
In addition, you can declare a global variable outside the function. It is worth noting that when you need to assign a new value to a global variable, you must use the "global" keyword, as follows:
When removing "Global TestMode", you can only set the variable to False in the some_function () function. If you want to share a global variable among multiple modules, you need to create a shared module file. Such as configuration.py, and find the variables you need in the file. Finally, import the sharing module.
View variable types
Check the face change type through the type () function, as shown below.
Commas in integer variables
A comma can be thought of as a sequence of variables, as shown below.
03. Operation numeric operation
Python supports basic numerical calculations of addition, subtraction, multiplication and division, as well as floor division (floor division), as shown below.
In addition, Python supports exponential operations (*), as shown below.
At the same time, Python can also perform division and remainder operations, as shown below.
String operation
String concatenation
String copy
String slicing
String reverse order
Negative index
If you want to get the last character of the string, you need to use a negative index, as shown below.
View index value
Regular expression
Split (): splits a string into a list through a regular expression.
Sub (): replace the character you want to match with a regular expression.
Subn (): replaces the character to be matched with a regular expression and returns the number of characters to be replaced.
Casting
Str (x): converts variable x to string type
Int (x): converts the variable x to an integer
Float (x): convert variable x to floating point
Set operation
A collection is an unordered collection of data that defines a collection variable, as shown below.
Set intersection
Gets the common portion of the two collections, as shown below.
Set difference
Get the different parts between the two collections, as shown below.
Set union
Gets the union of the two collections, as shown below.
Ternary operator
For writing conditional statements on one line, the syntax structure is [If True] if [Expression] Else [If False], as shown below.
04. Notes
Single-line comment
Multiline comment
05. Expression
Can be used for Boolean operations, such as:
Equality:==
Not Equity Equity
Greater: >
Less:=
Less or Equal:
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.