Print () function:
The default carriage return when passing in a single parameter, the keyword end can be used to avoid the output after the carriage return ( newline ), or to end the output with a different string.
>>> A, b = 0, 1>>> while B <: ... Print (b, end= ', ') ... A, B = B, a+b ... 1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
When multiple parameters are passed in, the output is separated by a space between multiple parameters.
>>> i = 256*256>>> print (' The value of I ', I) the value of I is 65536
List
It can be written as a comma-delimited list of values (items) in square brackets. Items in a list do not need to be of the same type.
Characteristics:
Just like the string index, the index of the list starts with 0, the list can be sliced, connected, and so on:
All slice operations return a new list containing the requested element
Unlike a string that is immutable *, it is possible to change a single element in the list. It is also possible to assign a value to a slice, which can even change the size of a string, or completely erase it:
The built-in functions are len()
also valid for lists
Nested lists (creating lists that contain other lists) are possible,
You can add something to the end of the list:
>>> q = [2, 3]>>> p = [1, q, 4]>>> len (p) 3>>> p[1][2, 3]>>> p[1][0]2>>& Gt P[1].append (' Xtra ') >>> p[1, [2, 3, ' Xtra '], 4]>>> q[2, 3, ' Xtra ']
In the last example, p[1]
and q
indeed point to the same object! We will go back to * object semantics *.
The print function and the list function in Python