1. Function range () is a python built-in function that can be used to create a list of integers, typically used in a for loop.
function syntax
Range(start, stop[, step])
Parameter description:
- Start: Count starts from start. The default is starting from 0. For example, range (5) is equivalent to range (0, 5);
- End: Count to end, but do not include end. For example: Range (0, 5) is [0, 1, 2, 3, 4] No 5
- Step: Step, Default is 1. Example: Range (0, 5) is equivalent to range (0, 5, 1)
If you need to traverse a sequence of numbers, you can use the built-in range () function. It generates a sequence of numbers, such as:
>>>for i in range(5):
... Print(i)
...
0
1
2
< Span class= "Hl-code" >3
< Span class= "Hl-code" >4
< Span class= "Hl-code" > You can also use range () function to create a list:
< Span class= "Hl-code" > >>>range (5)
< Span class= "Hl-code" > range (0, 5)
< Span class= "Hl-number" > < Span class= "Hl-number" >>>>list (range Span class= "Hl-number" >5) )
< Span class= "Hl-code" > < Span class= "Hl-builtin" >[0 , 1234]
< Span class= "Hl-number" > < Span class= "Hl-code" > 2. The function input () is also a python built-in function to receive user input. For input (), no matter what the user enters, it is treated as a string.
>>> x = input ("Please input information:")
Please input your information:my name is Zhangnian
>>> x
' My name is Zhangnian '
>>>
3. function print () is also a built-in function for presenting processing results or other information to the user. , the syntax format is:
Print (value, ..., sep= ', end= ' \ n ', File=sys.stdout,flush=false)
where the Sep parameter precedes the content that needs to be output; the SEP parameter is used to specify the delimiter between data, the default is a space, and the end is a newline output between data;
The file parameter is used to specify the output location, the default is the standard console, or you can override the output to a file.
>>> print ("hello,world!")
hello,world!
>>> print (' A ', ' B ', ' C ', sep= ' \ t ')
A b C
>>> print (1, 2, 3, sep= ' \ t ')
1 2 3
>>> for I in range (10):
... print (I, end= ")
...
>>> 0 1 2 3 4 5 6 7 8 9
>>> fp = open (' D:\\test.txt ', ' A + ')
>>> print (' hello,world! ', FILE=FP)
>>> Fp.close ()
>>>
4. The function eval () is a built-in function to execute a string expression and return the value of the expression. It can also be used to type conversions of user-entered content, such as:
>>> y = input (' Please input: ')
Please input:456
>>> y
' 456 '
>>> eval (' Y * 2 ')
' 456456 '
>>> z = 81
>>> eval ("z + 5")
86
>>> eval (' 3 + 3 ')
6
>>> eval (' Pow (3,3) ')
27
>>>
>>> y = input (' Please input: ')
Please input:654321
>>> y
' 654321 '
>>> type (y)
<class ' str ' >
>>> ID (y)
8580736
>>> Int (y)
654321
>>> eval (y)
654321
Range () \input () \print () \eval () in Python