This article was prepared for the ** In-house Workshop **. Therefore, please understand that we will proceed on the following assumptions.
The purpose is to allow participants to ** stand at the entrance where they can self-study as needed **.
The workshop basically focuses on hands-on. (Some explanations are included)
This workshop is expected to be ** 60-120 minutes **. Therefore, we do not do ** systematic learning ** because we do not have enough time for full-scale learning.
In order to be able to create the program you want from scratch in earnest, you need to study by yourself or take some kind of course.
This workshop is mainly aimed at the following participants.
Please note that there are many things that I do not dare to mention because I do not deal with intermediate and advanced people at all.
Please install either of the following. If you have the time, please install Anaconda.
** Note: You don't need to install both **
In the workshops so far, we have learned the following contents.
To review these, it is good to review the workshop, try to solve the problem here, or copy the example.
To be able to understand the concepts of "functions", "classes", and "objects" that are indispensable in modern programming, and to be able to create simple functions and classes.
By doing this, we aim to be able to utilize various modules and SDKs.
If possible, make sure you understand what you wrote later. However, you don't have to remember it perfectly.
Save the following script as exp411.py in the c: \ script folder and run it.
ex411.py
flag = True
# Part 1
if flag is True:
print("Test Python is True.")
else:
print("Test Python is False.")
# Part 2
if flag is True:
print("Test Python is True.")
else:
print("Test Python is False.")
# Part 3
if flag is True:
print("Test Python is True.")
else:
print("Test Python is False.")
Save exp411.py as exp412.py in the c: \ script folder, modify it, and then execute it.
ex412.py
flag = True
def printMsg():
if flag is True:
print("Test Python is True.")
else:
print("Test Python is False.")
printMsg()
Save exp412.py as exp413.py in the c: \ script folder, modify it, and then execute it.
ex413.py
F1 = True
F2 = False
def printMsg(flag):
if flag is True:
print("Test Python is True.")
else:
print("Test Python is False.")
printMsg(F1)
printMsg(F2)
Save exp413.py as exp414.py in the c: \ script folder, modify it, and then execute it.
ex414.py
F1 = True
F2 = False
def printMsg(flag, msg):
if flag is True:
print("Test Python is " + msg)
else:
print("Test Python is not" + msg)
printMsg(F1, "easy")
printMsg(F2, "difficult")
def function name():
Processing content
Function name()
def function name(argument):
Processing content
Function name(argument)
Save the following script as exp421.py in the c: \ script folder and run it.
ex421.py
ONES = "1"
ONEN = 1
if ONES == ONEN:
print("Same")
else:
print("Not Same")
Save exp421.py as exp422.py in the c: \ script folder, modify it, and then execute it.
ex422.py
SEVEN1 = 7
SEVEN2= "7"
print(SEVEN1 + int(SEVEN2))
print(str(SEVEN1) + int(SEVEN2))
print(SEVEN1 + SEVEN2)
An error will occur in the last sentence, but please proceed to the next hands-on.
Save exp422.py as exp423.py in the c: \ script folder, modify it, and then execute it.
ex423.py
ONES = "1"
ONEN = 7.0
if ONES:
print("ONES is True.")
else:
print("ONES is False.")
if ONEN:
print("ONEN is True.")
else:
print("ONEN is False.")
There are many other types, and different types are not considered to be the same data. See here for accurate information.
Embedded — Python 3.7.7 documentation
bool(variable)
str(variable)
int(variable)
float(variable)
The print statement can only pass a string type as an argument
The types that can be passed are generally determined for each function used in the same way.
Since conversion between Unicode and binary is complicated, it is omitted.
FLAG = "TEST"
if FLAG:
print("True")
else:
print("False")
Note: Depending on the programming language you use, the behavior may be slightly different.
Save the following script as exp431.py in the c: \ script folder and run it.
ex431.py
LIST = [10, 20, 'text']
print(LIST[0])
print(LIST[1])
print(LIST[2])
LIST[2] = 100
for i in LIST:
print(i)
Save exp431.py as exp432.py in the c: \ script folder, modify it, and then execute it.
ex432.py
DICT = { 'one': 1, 'two': 2, 's1': 'Text1', 's2': 'Text2'}
print(DICT['s1'])
print(DICT['two'])
for i in ['one', 'two', 's1', 's2']:
print(i)
print('---')
for i in DICT.keys():
print(DICT[i])
Save exp432.py as exp433.py in the c: \ script folder, modify it, and then execute it.
ex433.py
TUPLE = (1, 2, 'TEXT0')
for i in TUPLE:
print(i)
TUPLE[3] = 100
It doesn't matter if an error occurs, so proceed to the next step.
If you explain each as chitin, there are various things, so this time I will omit it just to know its existence.
Save the following script as exp441.py in the c: \ script folder and run it.
ex441.py
class TestClass:
x = 1
def show(self):
print(self.x)
objTest = TestClass()
print(objTest.x)
objTest.show()
Save exp441.py as exp442.py in the c: \ script folder, modify it, and then execute it.
ex442.py
class TestClass:
x = 1
def get(self):
print(self.x)
def set(self, val):
self.x = val
obj1 = TestClass()
obj1.get()
obj1.set(2)
obj1.get()
obj2 = TestClass()
obj2.get()
obj2.set("Obj2")
obj2.get()
obj1.get()
Save exp442.py as exp443.py in the c: \ script folder, modify it, and then execute it.
ex443.py
import requests
r = requests
# User-Agent
url = 'https://www.cloudgate.jp/ua.php'
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
header = { 'User-Agent': ua }
res = r.get(url, headers=header)
print("HTTP CODE: " + str(res.status_code))
print("HTTP BODY: " + res.text)
# GET PARAMETER
url = 'https://www.google.co.jp/search'
params = {'q': 'Qiita'}
res2 = r.get(url, params=params)
print(res2.url)
print(res2.text)
The image looks like this.
[](https: / /www.itmedia.co.jp/im/articles/0506/11/news011.html)
That said, if you have the documentation and usage examples, you may not be in trouble. However, understanding it will make it easier to deal with problems.
This should cover the basic terms.
However, we do not give details, so it is recommended that you read a technical book or practice with a collection of questions.
Also, if you create a script using API or SDK in this state, you will find many things that you do not understand. However, each time I read the documentation, I should be able to reach a level where I can understand it. By repeating them, you will be able to develop programs freely. let's do our best!
If you would like to continue learning, please make a request.
Recommended Posts