7.5.2乱数を生成するーーrandomモジュール>>> import random>>>>>> print(random.random())0.04692232975164723>>> print(random.randint(0, 10))2>>> print(random.randrange(0, 10, 2))2>>> print(random.uniform(1, 20))7.108838983664495>>> print(random.gammavariate(1 ...
もっと読む
2023年06月
Python勉強中 7.5その他の機能 20230627
7.5その他の機能7.5.1数学演算--mathモジュール+組み込み関数>>> import math>>>>>> print(abs(-100))100>>> print(math.ceil(1234.567))1235>>> print(math.floor(1234.567))1234>>> print(math.trunc(1234.567))1234>>> print(round(1234.567,2))1234.57>>> print(pow(2,4 ...
もっと読む
Python勉強中 7.4.3JSONデータを取得する 20230627
7.4.3JSONデータを取得するJavaScriputのオブジェクトリテラルというものをもとにしているデータ形式だそうです。>>> import requests>>>>>> res = requests.get('http://wings.msn.to/tmp/books.json')>>> bs = res.json()>>> print(bs['books'][0]['title'])独習Java 新版> ...
もっと読む
Python勉強中 7.4.2 HTTP POSTによる通信 20230626
7.4.2 HTTP POSTによる通信>>> import requests>>>>>> res = requests.post('https://wings.msn.to/tmp/post/.php',data={'name': '佐々木新之助'})>>> print(res.text)<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head> ...
もっと読む
Python勉強中 7.4HTTP経由でコンテンツを取得する 20230626
7.4HTTP経由でコンテンツを取得する7.4.1requestsモジュールの基本>>> import requests >>> >>> res = requests.request('get', 'https://codezine.jp/') >>> print(res.text) <!DOCTYPE html> <!--[if lte IE 8]> <html class="no-js lt-ie8" lang="ja"> <![ ...
もっと読む