I installed python and summarized the basic grammar flat. Make the article understandable just by looking at anyone who has worked on some PG language ** I would like to brush up each time **
■ Installation package
Download the required version (this time select the Windows x86-64 web-based installer for 3.7.7) and install it. ☑ of Install for all users has been removed. When completed, the file will be created below.
C:\Users\XXX\AppData\Local\Programs\Python
When the installation is complete, Python will be added to the menu as shown. Typical development support tools include PyCharm, Microsoft Visual Studio, and eclipse (PyDev add-in), but this page uses IDEL, which is the default installed development tool.
Select IDEL and start it. If you don't like the white screen, select Option → config IDLE → Highlights and select IDLE Dark.
Select File → New File to open another window.
Write the command statement in python in a separate window and execute Save (Ctrl + S) → Run Module (F5) to execute the process on the Shell screen.
I will briefly describe how to use it. Please refer to the comments for explanations. At least this is enough to make it readable.
#The comment is sharp.
#<Part 1: hello world ・ ・ ・ Do not put space before print, double-byte space is also prohibited>
print('hello world')
#<Part 2: Arguments of print function>
print('hello world',10,10.5) #Output with multiple arguments
print('hello world',10,10.5,sep=':') #Delimiter
#<Part 3: Variable (type is automatic conversion) and data input (if input, type will be Str even if you enter numbers)>
test = input('Please put something')
print(test) #Variable output
print((int(test))*1.08) #When calculating, convert str to int and calculate
#<Part 4: How to operate character strings>
test ='SAMPLE'.replace('A','I') #String replacement
print(test)
#<Part 5: Conditional branching>
test = input('Please put in a horse number')
if test.isdigit(): #Judgment of whether it is a numerical value(In the opposite case, if not)
umaban = int(test)
if umaban <6 : #6 or less(Conditional statement nesting)
print('The inner frame')
elif umaban <12 : #If 12 or less
print('Middle frame')
else: #If not less than 12
print('Outer frame')
else: #If not a number
print('Please enter a number')
#<Part 6: Loop for statement>
dayOfWeek =['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
for day in dayOfWeek : #All list of arrays
print(day)
print('--------------------')
for day in dayOfWeek[1:6] : #List of arrays 2nd to 5th
print(day)
print('--------------------')
for test2 in range(5) : #Repeat 5 times
print(test2)
test2 = test2 + 1
print('--------------------')
for test3 in range(6,11) : #6 repeats up to 10 times
print(test3,'counter')
test3 = test3 + 2 #Experiment. test3
print(test3,'When manually added')
print('--------------------')
#<Part 7: Definition of function>
def method1(): #No arguments
print('Everyone','Comment 1')
def method2(other): #With arguments
print(other,'Comment 2')
method1()
method2('Hogehoge')
print('--------------------')
that's all.
Recommended Posts