投稿

Generators

import random def lottery(): # returns 6 numbers between 1 and 40 for i in range(6): yield random.randint(1, 40) # returns a 7th number between 1 and 15 yield random.randint(1,15) # returns a 8th number between 100 and 120 yield random.randint(100,120) for random_number in lottery(): print("And the next number is... %d!" %(random_number)) ========= RESTART: C:/python/lottery20210222.py ======== And the next number is... 25! And the next number is... 25! And the next number is... 16! And the next number is... 38! And the next number is... 22! And the next number is... 4! And the next number is... 9! And the next number is... 115! >>>

About Interactive Tutorials(learnpython.org)

learnpython.org is a free interactive Python tutorial - one of the Interactive Tutorials websites. Interactive Tutorials is a personal project of mine aimed at making everyone in the world be able to learn how to code for free. The servers used to run the tutorials and the time invested in writing tutorials is funded through ads. The vision is to teach coding within the browser using short and effective exercises. By running actual code directly from the web browser, students are able to try out coding without installing and executing it locally, which can be hard and redundant for the purpose of learning how to code. This creates a more efficient learning process, because students focus on learning instead of setting up coding environments. This website and its content may be used freely and without charge, and it will always be free. source from here

pandas DataFrames Basic

Pandas is a high-level data manipulation tool developed by Wes McKinney. It is built on the Numpy package and its key data structure is called the DataFrame. DataFrames allow you to store and manipulate tabular data in rows of observations and columns of variables. There are several ways to create a DataFrame. One way way is to use a dictionary. For example: dict = {"country": ["Brazil", "Russia", "India", "China", "South Africa"], "capital": ["Brasilia", "Moscow", "New Dehli", "Beijing", "Pretoria"], "area": [8.516, 17.10, 3.286, 9.597, 1.221], "population": [200.4, 143.5, 1252, 1357, 52.98] } import pandas as pd print(dict) brics = pd.DataFrame(dict) print(brics) brics.index = ["BR", "RU", "IN", "CH", "SA"] print(brics) ===== RESTART: C:/python/PandasDataFrames...

pip list (Vostro 15 3000)

C:\Users\ooshi>python -m pip install --upgrade pip Requirement already satisfied: pip in c:\users\ooshi\appdata\local\programs\python\python39\lib\site-packages (21.0.1) C:\Users\ooshi>pip list Package Version ------------------------- --------- altgraph 0.17 cycler 0.10.0 et-xmlfile 1.0.1 future 0.18.2 jdcal 1.4.1 kiwisolver 1.3.1 matplotlib 3.3.3 numpy 1.19.4 openpyxl 3.0.5 panda3d 1.10.8 pandas 1.2.2 pefile 2019.4.18 Pillow 8.1.0 pip 21.0.2 pygame 2.0.1 pyinstaller 4.2 pyinstaller-hooks-contrib 2020.11 pyparsing 2.4.7 python-dateutil 2.8.1 pytz 2021.1 pywin32 300 pywin32-ctypes 0.2.0 reportlab ...

Python keyword 36

>>> import keyword >>> dir(keyword) ['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'iskeyword', 'issoftkeyword', 'kwlist', 'softkwlist'] >>> keyword.iskeyword("for") True >>> keyword.issoftkeyword('for') False >>> keyword.softkwlist [] >>> keyword.kwlist ['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', ...

Python | Menu widget in Tkinter

イメージ
Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used package for GUI applications which comes with the Python itself. Menus are the important part of any GUI. A common use of menus is to provide convenient access to various operations such as saving or opening a file, quitting a program, or manipulating data. Toplevel menus are displayed just under the title bar of the root or any other toplevel windows. # importing only those functions # which are needed from tkinter import * from tkinter.ttk import * from time import strftime # creating tkinter window root = Tk() root.title('Menu Demonstration') # Creating Menubar menubar = Menu(root) # Adding File Menu and commands file = Menu(menubar, tearoff = 0) menubar.add_cascade(label ='File', menu = file) file.add_command(label ='New File', command = None) file.add_command(label ='Open...', command = None) file.add_command(l...

Python Tkinter – ScrolledText Widget

イメージ
Tkinter is a built-in standard python library. With the help of Tkinter, many GUI applications can be created easily. There are various types of widgets available in Tkinter such as button, frame, label, menu, scrolledtext, canvas and many more. A widget is an element that provides various controls. ScrolledText widget is a text widget with a scroll bar. The tkinter.scrolledtext module provides the text widget along with a scroll bar. This widget helps the user enter multiple lines of text with convenience. Instead of adding a Scroll bar to a text widget, we can make use of a scrolledtext widget that helps to enter any number of lines of text. # Python program demonstrating # ScrolledText widget in tkinter import tkinter as tk from tkinter import ttk from tkinter import scrolledtext # Creating tkinter main window win = tk.Tk() win.title("ScrolledText Widget") # Title Label ttk.Label(win, text = "ScrolledText Widget Example insert"...