Many of the Python list examples do not know what is going on. In fact, this is a very interesting thing. This is also one of the reasons why many developers are infatuated with the Python language. Next, let's take a detailed look at how to solve the relevant problems.
- Basic Environment Test for Python Programming
- How does Python IDE adapt to the current turbulent market
- Performance Comparison Between the Python programming language and Java
- Summary of advantages in the use of Python Programming Language
- Python for beginners
Generally, programmers Fall In Love With Python because it increases productivity. Since there is no compilation process, the edit-test-debugging cycle is quite fast. Debugging a Python program is simple: An error will never lead to a segment error. When the interpreter finds an error, it raises an exception. When the program does not catch exceptions, the interpreter prints a stack trace. A source code-level debugger allows us to check local and global variables, calculate expressions, set breakpoints, and perform single-step tracking. The debugger is written in Python, which proves Python's ability. In addition, the fastest way to debug the program is to add several print statements: Quick edit-test-debugging cycle makes this simple method very effective.
Basic calculation formula of the Python list Example
Let's start with the subject and teach you how to use Python. I assume that the reader has the foundation of other languages and can directly focus on the syntax.
- 1 a = 0
- 2 B = 7
- 3 aa = a + 1
- 4 a = B *
- 5 print
- Result: 7
The above is a simple example of python. I believe that if you have learned other languages (such as C/C ++ and Java), you can easily understand it.
- A + B
- A-B A minus B
- A * B a multiplied by B
- A/B a except B
- A % B obtain the remainder of A/B (for example, 8% 3 = 2)
- -A: Obtain the inverse number of a (if A = 7,-A =-7)
- String
- 1 a = 'hello'
- 2 B = "world"
- 3 c = a + ''+ B + '!! '
- 4 print c
Result: hello world !!
String can be enclosed by the 'or "symbol. Row 3 is an example of merging four string objects and connecting the four strings to a single string.
- 1 a = '%s=%d' % ('test', 16)
- 2 print a
Result: test = 16
Similar to C/C ++'s printf or sprintf. In line 1, python provides the string format function. String '% s = % d' specifies the format of the string, followed by % after the string, followed by the format parameter, these parameters will replace % s and % d in format in sequence. % S indicates that the string is to be replaced, and % d is to be replaced with an integer.
- a = 'This is a rather long string containing\n\
- several lines of text just as you would do in C.\n\
- Note that whitespace at the beginning of the line is\
- significant.\n'
String can be extended to several rows, but escape \ is required at the end of each row to ignore newline. You can also use "" Or '''
- a = '''This is a rather long string containing
- several lines of text just as you would do in C.
- Note that whitespace at the beginning of the line is
- significant.'''
You do not need to create an escape when using ''' or ", but newline will contain string content.
- List
- 1 a = []
- 2 a[0] = 'aoo'
- 3 a[1:3] = [10, 11]
- 4 b = [1, 2, 3, 'foo']
- 5 print a, b, b[:3], b[1:]
The results show that [9, 10, 11] [1, 2, 3, 'foo'] [1, 2, 3] [2, 3, 'foo']
The above is the use of the Python list Example. List is a sequence data type, which is similar to the array of C/C ++, but array is fixed length, while list is not. Its length can be changed at any time. Line 1 shows bind a as an empty list. Row 2 specifies that index 0 is 'aoo' string object. Example of using slice with row 3 as list. Replace item (index 1 and 2) between index 1 and index 3 with 10 and 11. B [: 3] of Row 5 is equivalent to B [0: 3], while B [1:] is equivalent to B []. The items in the list do not need to be of the same type. In the above example, items in a list object can contain integers and items of different types.