If you want output this sentence "I am 22 years old."
And your code will be
print("I am " + str(a) + "years old.")#Either "" or '' is ok.
There are the correct codes.
About Python List
1. if you want to output the last element in the list, you can use this code:
list[-1]#in this place, list means the name of this list
Similarly, if you want to input the second to last number, you can use:
2. some methods to modify, add or delete elements.
· modify the element:
sights='Beijing' means change the first element in the list sights to Beijing.
· add element:
sights.append('Beijing') means add Beijing to the last of the list sights, sights.
insert(1, 'Beijing') means add Beijing to the place between the first element and the third element.
· delete element:
del sights means delete the first element from the list.
poped_sight=sights.pop() means we can still use it when we delete the last element.
One thing to be noted, if we use poped_sight=sights.pop(1), it means that we still use the second element when we delete it.
sights.remove('Beijing') means delete the Beijing from the list. (If there are many Beijing in the list, this method only can delete the first Beijing.)
· sort & alphabetically forever: use sort()
For example, sight.sort().
If we use sight.sort(reverse =True), it means reverse order.
· temporary sort: use sorted() function.
For example, print(sorted(sights)).We can also use sorted(sights, reverse = True) to reverse order.
· reverse order print: sights.reverse()
· How to know the length of the list? The answer is use len() function.