[PYTHON] Learning record (1st day)

I will record what I learned in programming from today

There are three reasons why I decided to record what I learned.

  1. To make daily programming learning more efficient by being aware of the output
  2. To be able to look back on what you have learned in the past
  3. For continuous learning by recording daily

content of study

How to write Qiita articles

Since it was Markdown notation with some experience on GitHub, I checked the notation as a review. Since this is the first article, I used as many notations as possible.

Python basics

Even though I'm new to Python, I wondered if I could start scraping suddenly. However, after studying programming for two years at university, I couldn't continue studying from scratch about variables, functions, branches, etc., so I didn't have to do scraping and machine learning to learn Python grammar. I decided to study at the same time. The following is a very basic content, but I will summarize what I learned today.

Comment out

It was a comment-out description method different from the experienced C, Java, and Swift.

Description example
# One line comment out
Description example
"""
 By double quotes
 Comment out multiple lines
"""

'''
 By single quote
 Comment out multiple lines
'''

Loop processing

A description method similar to the Java extension for statement

Description example
    num = [0, 1, 2, 3]

 #Loop statement
    for a in num:
        print(a)

Execution result

0 1 2 3

lambda expression

In Python, function names are treated in the same way as variable names. Useful when defining small functions.

Description example
bai_print = lambda x: print(x*2)

bai(2)
bai(10)

Execution result

4 20

Scraping with Python

I learned scraping using ʻurllib`. Below is a summary of the functions in the urllib library that I learned today and their usage examples.

import urllib.request as req
import urllib.parse as par

url = "https://uta.pw/shodou/img/28/214.png "
savename = "test.png "

# urlretrieve (URL of file, file name of save destination)
# Function to download a file on the web
# https://uta.pw/shodou/img/28/214.pngにあるpngファイルがtest.pngという名前で保存される
req.urlretrive(url, savename)


# urlopen (file URL)
# Read data with read (), a function that opens URL resources
# Files on the web are saved in Python memory
mem = req.urlopen(url).read()


# urlencode (parameter to convert to URL)
# Create a query from parameters and create a URL for the request
# https://api.aoikujira.com/zip/xml/get.php?fmt=xml&zn=1500042というURLが生成される
API = "https://api.aoikujira.com/zip/xml/get.php"

values = {
    'fmt' = 'xml'
    'zn' = '1500042'
}
params = par.urlencode(values)

url = API + "?" + params

Summary

This time I wrote an article for the first time using various notations, but since it takes a while and it is a waste of time, I will write it concisely as long as it stays in the learning record from tomorrow onwards.

Recommended Posts

Learning record (1st day)
Learning record No. 27 (31st day)
Learning record 5 (9th day)
Learning record 6 (10th day)
Programming learning record day 2
Learning record 8 (12th day)
Learning record 1 (4th day)
Learning record 7 (11th day)
Learning record 2 (6th day)
Learning record 16 (20th day)
Learning record 22 (26th day)
Learning record No. 24 (28th day)
Learning record # 3
Learning record # 1
Learning record # 2
Learning record No. 19 (23rd day)
Learning record No. 29 (33rd day)
Learning record No. 28 (32nd day)
Learning record No. 23 (27th day)
Learning record No. 25 (29th day)
Learning record No. 26 (30th day)
Learning record No. 20 (24th day)
Learning record No. 14 (18th day) Kaggle4
Learning record No. 15 (19th day) Kaggle5
Learning record 11 (15th day) Kaggle participation
Python learning day 4
Learning record (2nd day) Scraping by #BeautifulSoup
Linux learning record ① Plan
<Course> Deep Learning: Day1 NN
Subjects> Deep Learning: Day3 RNN
1st month of programming learning
Competitive professional devotion record Day 4-6 (10 / 18,22,23)
Learning record (3rd day) #CSS selector description method #BeautifulSoup scraping
Thoroughly study Deep Learning [DW Day 0]
Deep Learning Specialization (Coursera) Self-study record (C2W1)
Deep Learning Specialization (Coursera) Self-study record (C1W2)
Introduction to discord.py (1st day) -Preparation for discord.py-
Deep Learning Specialization (Coursera) Self-study record (C3W2)
[Leet Code learning record] Solved ZigZag Conversion
Deep Learning Specialization (Coursera) Self-study record (C2W2)
Learning record of reading "Deep Learning from scratch"
Deep Learning Specialization (Coursera) Self-study record (C4W1)
Deep Learning Specialization (Coursera) Self-study record (C2W3)
[Rabbit Challenge (E qualification)] Deep learning (day4)
Deep Learning Specialization (Coursera) Self-study record (C4W2)