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 > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the python interpreter". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use the python interpreter.
1. Python tutorial
Based on the continuous interpretation of python3.10, it aims to quickly recall and deepen understanding and save your own time cost.
1.1 Overview
Python is an easy-to-learn programming language that provides efficient high-level data structures and simple and effective object-oriented programming.
Because of the nature of elegant syntax, dynamic typing, and interpretive language, it is an ideal language for scripting and rapid development of applications on most platforms. The following summary is based on python10.
1.2 python standard library
A large number of modules written in Python provide standard solutions to many problems in daily programming.
The catalogue is as follows:
Overview, built-in functions, built-in constants, built-in types, built-in exceptions,
Text processing services, binary data services, data types, digital and mathematical modules, functional conversion modules, file and directory access, data persistence, data compression and archiving
File formats, encryption services, common operating system services, concurrent execution, network and interprocess communication, Internet data processing, structured tag processing tools, Internet protocols and support, multimedia services
Internationalization, program framework, TK graphical user interface (GUI), development tools, debugging and analysis, software packaging and distribution, python runtime services, custom python parsers, python language services
Import module, windows system related module, Unix proprietary service, replaced module,
1.3 python language reference Manual
The syntax and "core semantics" of Python are introduced. While striving to be concise and to the point, we also try to be accurate and complete, overview, lexical analysis, data model, execution model, import system, expressions, simple statements, compliance statements, top-level components, complete syntax specifications
1.4 python package Index 1.5 terms comparison Table 2, dessert before class
Python is simple and easy to use, but it is a true programming language, providing a large number of data structures and supporting the development of large programs, far more than shell scripts or batch files.
Python programs are simple and easy to read, and are usually much shorter than C, C++, and Java codes that implement the same function for the following reasons:
Advanced data types allow complex operations to be expressed in a single statement
Use indentation instead of parentheses to group code blocks
There is no need to predeclare variables or parameters.
Python "Extensible": by developing C language programs, you can quickly start adding new built-in functions or modules to the interpreter, whether it's letting the core program run at top speed, or linking Python programs to libraries that provide only precompiled programs (for example, hardware graphics libraries). With a little effort, you can link the Python interpreter with an application developed in C, and use it to extend and control the application.
3. Python parser 3.1 pass in parameters
Tiaoce.py
Import sysa = sys.argv [0] b = sys.argv [1] c = sys.argv [2] # specify the value of language on the command line, and the file is away from the output languageif b.split ("=") [0] = = "language": C = b.split ("=") [1] print ("value of the first string after the script:" + c) else: print ("your first parameter name is incorrect Should be language ") # the above three variables can be passed as arguments to the function to the subsequent program def tiaoce (" script name: "+ a) print (" the first string after the script: "+ b) print (" the second string after the script: "+ c) tiaoce (aline bpenc)
Expected:
C:\ Users\ mc\ Desktop\ python Foundation > value of the first parameter after python tiaoce.py language=jiao aa bb script: jiao script name: first string after tiaoce.py script: second brother string after language=jiao script: jiao3.2 interactive run C:\ Users\ mc > pythonPython 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32Type "help", "copyright" "credits" or "license" for more information. > > aa = True > if aa:... Print ("jiaotengfei").. Jiaotengfei > > 3.2.1 executable Python script
Execute on linux: the Python script can be executed directly, just like the shell script, with the first line added:
#! / usr/bin/env python3.5$ chmod + x myscript.py
Execute on windows10: right-click the py file, open it and select python. Double-click will automatically execute tiaoce.py.
Print ("jiao") a = input ("Please enter information:") print (a) 3.2.2 Interactive Startup File
When you use Python interactively, some standard commands are executed every time you start the interpreter, which is usually convenient. You can do this by setting the environment variable named PYTHONSTARTUP to the file name that contains the startup command. This is similar to the .profile feature of Unix shell.
Import osfilename = os.environ.get ('ANDROID_HOME') # print the value of your environment variable Print (filename) # anticipates "" D:\ Program Files\ android-sdk-windows "filename = os.environ.get ('PYTHONSTARTUP') print (filename) if filename and os.path.isfile (filename): with open (filename) as fobj: startup_file = fobj.read () print (startup_file) exec (startup_file) 3.3 the operating environment of the interpreter (character encoding of the source file)
By default, the encoding of the Python source file is UTF-8. If the default encoding is not used, the encoding of the file is declared and the first line of the file is written as a special comment. The syntax is as follows:
# encoding can be any kind of codecs supported by Python. # (this module defines the base class of standard Python codecs (encoders and decoders) #-*-coding: encoding-*-# declares the use of Windows-1252 encoding #-*-coding: cp1252-*-
The first line definition of the executable python file:
#! / usr/bin/env python3#-*-coding: cp1252-*-at this point, I believe you have a better understanding of "how to use the python interpreter". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.