num = [3,5,9,0,1,9,0,3]
num.reverse()
print(num)
reverse: used to reverse a list
Can be used with sort
to provide reverse sorting, as shown below:
a = [1,3,4,2,6,1,5,2,7]
a.sort(reverse=True)
print("The list a is:",a)
The output is:
The list a is: [7, 6, 5, 4, 3, 2, 2, 1, 1]
I am a separator~
a=input()
c=a.split()
split: slices the values received in the list according to spaces
You can also do it like this:
a=input().split()
str1 = str.pop(0)
pop: used to delete the element at index 0 of the list
I am a separator~
print(len(str.split( )))
len: calculates the length of the list
I am a separator~
i = input().split()
a = i[0:10]
print(a)
Outputs the elements from index 0 to index 9 in the list
Example:
Input: 1 2 3 4 5 6 7 8 9 0 11 12
Output: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
I am a separator~
offer_list = ["qwe","asd","zxc"]
for i in offer_list:
print("%s, hello"%i)
Prints the elements in the list offer_list one by one in the %s
The output of the above code is:
qwe, hello
asd, hello
zxc, hello
I am a separator~
i = [1,2,3,4]
i.append(6)
append: adds the element in the parentheses to the end
The output of the above code is:
[1,2,3,4,6]
I am a separator~
print(a[-4:])
can output the last four values in the list
Example:
#Code:
a = ['P', 'y', 't', 'h', 'o', 'n']
print(a[3])
print(a[-4:])
The output is:
h
['t', 'h', 'o', 'n']
I am a separator~