current position:Home>Python interface automation test framework (basic) -- basic syntax
Python interface automation test framework (basic) -- basic syntax
2022-01-31 09:42:41 【I am the white moonlight you can't get】
「 This is my participation 11 The fourth of the yuegengwen challenge 10 God , Check out the activity details :2021 One last more challenge 」
Preface
The author's python The basics of programming has written about functions and built-in functions , Although I didn't say it python How much writing grammar , Write code, talk about concepts, and then demonstrate with code , The author acquiesces that readers should or self-study python Basics , But for most of Xiaobai's classmates, they may be at a loss , Therefore, a basic grammar is specially added to solve doubts .
Basic grammar
code
python The language used in most cases is recognized as a scripting language , Because it can be used with the smallest py Run as a module , No compilation required , It's very convenient to use it immediately , stay linux The environment is like a fish in water ; Therefore, its beginning needs to have the beginning of coding format , But it defaults to utf-8 Coded Unicode character string , So I often don't see this line ; Of course, you can specify other formats if necessary Unicode Coding format
# -*- coding: utf-8 -*-
Copy code
identifier
Identifiers are variables 、 Class name 、 A general term for method names , Not as an individual ; Then there are several special points to pay attention to :
- Must be in letters or _ Start with an underline , It can't be a number 、$ The beginning of the dollar sign
- Other parts after the beginning can have letters 、 Numbers 、 Underline composition
- Identifiers are case sensitive
Identifier naming rules
Rules matter , Don't mess up , It's better to see the name and the meaning ; The second is the writing rules , Improve readability
- Follow identifier naming rules : Must be letters or underscores _ start
- Between variables and values = The assignment symbol has a space :a = 1
- If the variable is long , Use underscores to connect :first_name = "Joe"
- The class name specification suggests that the name of the big hump , Capitalize the first letter of a word :class MyFirstClass:
- The method name is the same as the variable name , If there is inheritance , Try to avoid _ or __ Name at the beginning
- Little hump nomenclature , Less in python See you in :firstName
- All variable or method names , Try not to use built-in keywords to name , Lest success cover
- python Provides a keyword modular , There are all keywords in it ( Reserved words )
import keyword
print(keyword.kwlist)
# Output :['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Copy code
notes
Develop good coding habits , Write notes for your convenience , Not the next one .
- Single-line comments , Use # Well No
# This is a line of comments , Will not be output
a = 1
print(a) # This is the second line of comment
# Output :1
Copy code
- Multiline comment , Three single or double quotation marks in pairs
''' The comments here will not be output during the running of the program '''
""" This also means multi line comments """
print("Hello World!")
Copy code
Lines and indents
The author is learning python When , Almost crazy by its indentation , One is really not used to ( from java To python The transformation of ), Second, there is no good use of IDE Editing tools
- That's ok , If there are no special circumstances , The code should be aligned with the top grid , If there is , Then you need to indent , It has no {} Such symbols represent blocks of code
a = 1
b = 2
for i range(10):
print(a) # It's wrong here , It's a new line , stay : Subsequent blocks of code must be indented
print(a) # For for Yes, there is 4 A space
Copy code
- Multiple lines , A string variable or other type , If you want to represent it as a line, you need to use \ Symbol
a1 = " Here is a long string , If it is too long, it will affect the appearance , You need to wrap to beautify "
print(a1)
a2 = " Here is a long string ,\ If it is too long, it will affect the appearance ,\ You need to wrap to beautify "
print(a2) # The output is the same
Copy code
Input and output
- input(), Input function ,python Use... When interacting with clients , The input is a string type
- print(), Output function , You can format and output any data type ; Later, we will talk about string formatting output
One line shows multiple statements
- stay python in ; Semicolons are separators
import sys;print(sys.__doc__)
# Output sys All methods, attributes and usage instructions in the module
Copy code
Guide pack
This is used in encapsulation or reference , The format is import、from...import; The main function is to introduce external modules or third-party libraries , That is not in this py Defined in module , External libraries need to be introduced
import sys
print(sys.platform) # Output the system of the current environment :win32
Copy code
summary
python The grammatical basis of programming , It's over here , More and more interesting knowledge will be introduced later ; At the same time python Learning from , Don't limit yourself to reading 、 read 、 Go to the Forum , It should be practice more often 、 Constantly consolidate the basic knowledge , The foundation is not solid 、 The earth trembled and the mountains swayed , Remember !
copyright notice
author[I am the white moonlight you can't get],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201310942373987.html
The sidebar is recommended
- Django ORM details - fields, attributes, operations
- Python web crawler - crawling cloud music review (3)
- Stroke list in python (bottom)
- What cat is the most popular? Python crawls the whole network of cat pictures. Which one is your favorite
- [algorithm learning] LCP 06 Take coins (Java / C / C + + / Python / go / trust)
- Python shows the progress of downloading files from requests
- Solve the problem that Django celery beat prompts that the database is incorrectly configured and does not support multiple databases
- Bamboolib: this will be one of the most useful Python libraries you've ever seen
- Python quantitative data warehouse construction 3: data drop library code encapsulation
- The source code and implementation of Django CSRF Middleware
guess what you like
-
Python hashlib module
-
The cover of Python 3 web crawler development (Second Edition) has been determined!
-
The introduction method of executing Python source code or Python source code file (novice, please enter the old bird and turn left)
-
[Python basics] explain Python basic functions in detail, including teaching and learning
-
Python web crawler - crawling cloud music review (4)
-
The first step of scientific research: create Python virtual environment on Linux server
-
Writing nmap scanning tool in Python -- multithreaded version
-
leetcode 2057. Smallest Index With Equal Value(python)
-
Bamboolib: this will be one of the most useful Python libraries you've ever seen
-
Python crawler actual combat, requests module, python realizes capturing a video barrage
Random recommended
- [algorithm learning] 1108 IP address invalidation (Java / C / C + + / Python / go / trust)
- Test platform series (71) Python timed task scheme
- Java AES / ECB / pkcs5padding encryption conversion Python 3
- Loguru: the ultimate Python log solution
- Blurring and anonymizing faces using OpenCV and python
- How fast Python sync and async execute
- Python interface automation test framework (basic) -- common data types list & set ()
- Python crawler actual combat, requests module, python realizes capturing video barrage comments of station B
- Python: several implementation methods of multi process
- Sword finger offer II 054 Sum of all values greater than or equal to nodes | 538 | 1038 (Java / C / C + + / Python / go / trust)
- How IOS developers learn python programming 3-operator 2
- How IOS developers learn python programming 2-operator 1
- [Python applet] 8 lines of code to realize file de duplication
- Python uses the pynvml tool to obtain the working status of GPU
- Data mining: Python actual combat multi factor analysis
- Manually compile opencv on MacOS and Linux and add it to Python / C + + / Java as a dependency
- Use Python VTK to batch read 2D slices and display 3D models
- Complete image cutting using Python version VTK
- Python interface automation test framework (basic) -- common data types Dict
- Django (make an epidemic data report)
- Python specific text extraction in actual combat challenges the first step of efficient office
- Daily python, Part 8 - if statement
- Django model class 1
- The same Python code draws many different cherry trees. Which one do you like?
- Python code reading (Chapter 54): Fibonacci sequence
- Django model class 2
- Python crawler Basics
- Mapping 3D model surface distances using Python VTK
- How to implement encrypted message signature and verification in Python -- HMAC
- leetcode 1945. Sum of Digits of String After Convert(python)
- leetcode 2062. Count Vowel Substrings of a String(python)
- Analysis of Matplotlib module of Python visualization
- Django permission management
- Python integrated programming -- visual hot search list and new epidemic situation map
- [Python data collection] scripy realizes picture download
- Python interface automation test framework (basic part) -- loop statement of process control for & while
- Daily python, Chapter 9, while loop
- Van * Python | save the crawled data with docx and PDF
- Five life saving Python tips
- Django frequency control