test.py
list = ["0", "1", "2"]
#Close to Ruby's array handling
list[0]
#0th"0"Is taken out.
test.py
def test(arg):
return arg + 1
print(test(0))
#The function is test and the argument is arg.
#In the case of a function, the return value by return is required.
In the above case, enter * arg * of the function * test * with * 0 * of * test (0) * as an argument,
test.py
for index in range(100)
print index
#Output numbers from 0 to 99 times
for i in range(1,101)
print index
#Specify the range from 1 to 100 times
#It is customary to use index or i between for and in.
#For statement by list
num = 0
list = ["0", "1", "2"]
for item in list:
print list[num]
num += 1
#Everything is done for the contents of the list. In the case of a list, item is usually between for and in.
test.py
num = 1 #Initialize counter variable
while num <= 10:
print(num)
num += 1 #Update counter variable
The * num * part before * while * is called the counter variable, and it is handled by the conditional expression after * while *. If you do not update num in the while statement and specify something that does not apply to the conditional expression, it will loop.
with(open)
test.py
# with open('File to reference', 'Execution process called mode') as file:
#Description of the process to be executed
For example, if there is a test.txt file in the directory directly above test.py ./test.txt You can specify the reference destination by writing. In addition, in the execution process called mode, ** r **, which is an acronym for read, and ** w **, which is the acronym for write, is the execution process that skips the mode. (Detailed content will be learned from the next time onwards)
class
test.py
#class Class name (uppercase):
# def __init__(self,Property 1,Property 2, ...,):
# self.Property 1=Property 1
#def method name(self):
#return Process to be executed
#Example
class Card: #Class called Card
def __init__(self, date, user_name):
self.date = date
self.user_name = user_name
def message(self): #The function in the class is called a method, this time the method called message
return self.user_name + self.date #Method return value
date_a = '2020-01-01'
user_name_a = 'Test'
card_a = Card(date_a, user_name_a) #Card in the Card class_Create an instance called a
print(card_a.message()) #card_The message method is executed for a and print is output.
(1) When I wrote the code in VScode and prepared an environment where it can be executed in the terminal, an error occurred when I executed it, so a memorandum. If you do not describe # coding: utf-8, you will get an error due to using Japanese. ② Reserved words are also in Python ③ You can tell whether it is str type or int type by print (type (what you want to check)). ④ There is a Boolean type that is neither str nor int. Example: T = True, N = False ⑤ You can search for modules from the outside by searching with pypi for modules that can be imported. Famous places like NumPy, Pandas, Flask, Django, etc.