I am studying by personally using a service of Bee Proud called "PyQ" to strengthen Python. This can be programmed with a browser without creating an environment. Also, one of the features is that you can learn the technique by copying the basic grammar. In addition to grammar for beginners, there are also unit tests and web courses using Django that you might use in practice.
I will summarize not only the sutras but also the grammar learned in PyQ to output.
list The list is created as follows.
test = ['hoge','fuga','hege']
The value set in list is called an element. Elements start at 0.
test = ['hoge','fuga','hege']
print(test[0]) #hoge is output
print(test[1]) #fuga is output
print(test[2]) #hege is output
If you want to add an element to the end, use append.
test = ['hoge','fuga','hege']
test.append('test')
print(test[3]) #test is output
If you want to add it in the middle, use insert.
test = ['hoge','fuga','hege']
test.insert(1,'test')
print(test[1]) #test is output
Use pop () to remove an element from the end. If you want to delete an element in the middle, use pop (index).
test = ['hoge','fuga','hege']
test.pop()
for item in test:
print(item) #hoge and fuga are output
Specify the element you want to change and enter it.
test = ['hoge','fuga','hege']
test(0) = 'test'
print(test[0]) #test is output
The structure of the for statement that combines list is as follows.
for variable in list:
print(variable)
The values entered in list are output sequentially.
test = [1,2,3]
for item in test:
print(item)
#The output looks like this
# 1
# 2
# 3
Next time, I will output what I learned about handling dictionary-type data.
Recommended Posts