python
sky-影
这个作者很懒,什么都没留下…
展开
-
迭代器
标准的迭代器接口有两个方法:__next__:返回一个可用元素,没有的时候抛出stoplteration异常__iter__:返回self,以便在应该使用可迭代对象的地方使用迭代器,例如for循环中。class eg: def __init__(self,text): self.text = text self.sub_text = text....原创 2020-01-07 22:58:59 · 169 阅读 · 0 评论 -
功能性模块 提取句子的每一个单词
class word: def __init__(self,text): self.text = text self.sub_text = text.split(" ") def __getitem__(self,index): if self.sub_text[index].isalpha(): retur...原创 2020-01-07 22:22:27 · 221 阅读 · 0 评论 -
功能性代码块 *kwargs 和 **kwargs
# #插入操作# s = []# def insert():# a = 0# while a < 4:# values = input("enter a world: ")# s.append(values)# a += 1# print(s)# insert()# # #加强版# s = ...原创 2020-01-07 11:40:44 · 206 阅读 · 0 评论 -
jupyter notebook basic for python (other)
# def p(a):# d = a + " " + a# return d# print(p("new days"))# type(print("did again"))# ## def twogril(one,two):# result = "I love " + one.title() + " " + two.title()# # print(result)# ...原创 2020-01-07 11:38:47 · 245 阅读 · 0 评论 -
简单代码引申出来的思考
#原代码,判断帽子的颜色def hat_available(color): hat_colors = 'black, red, blue, green, white, grey, brown, pink' return(color.lower() in hat_colors)have_hat = hat_available('green') print('hat ava...原创 2020-01-06 15:19:24 · 183 阅读 · 0 评论 -
jupyter notebook for python (七)
(1)String formatting methodsthe following methods are applied to string objects.capitalize()- capitalizes the first character of a string .lower()- all characters of a string are made lowerca...原创 2020-01-06 00:17:36 · 207 阅读 · 0 评论 -
jupyter notebook for python (六)
Boolean string testsmethods.isalpha() .isalnum() .istitle() .isdigit() .islower() .isupper() .startswith()typestrhas methods that return a Boolean (True or False) for different tests on t...原创 2020-01-06 00:02:33 · 94 阅读 · 0 评论 -
jupyter notebook for python (六)
(1)function input()(2)note:input()returns a string (type = str) regardless of entryif a string is enteredinput()returns a string if a number is enteredinput()returns a string[ ]...原创 2020-01-05 16:44:32 · 137 阅读 · 0 评论 -
jupyter notebook for python (四)
(一)Addition: Numbers and StringsNumeric additionNumeric additionSingle linemath equations, run in a code cell, will output a sum# adding a pair of single digit Integers3 + 5 String additi...原创 2020-01-05 16:14:14 · 172 阅读 · 0 评论 -
jupyter notebook for python (三)
(一)内置函数的简单使用Using the Pythontype()functiontype()returns the data type of python objectsstr,int,floatWhat does usingtype()reveal?str: whentype()returnsstrthat means it has evaluate...原创 2020-01-05 10:58:24 · 142 阅读 · 0 评论 -
jupyter notebook for python (二)
(一)字符串(string):A String is a commontypeof data, used in programming, consisting of a sequence of 1 or more characters.A String is a sequence of characters(aka: astringof characters) Chara...原创 2020-01-05 10:23:05 · 183 阅读 · 0 评论 -
jupyter notebook (一)
(一)如何运行:Click in the cell belowandpress "Ctrl+Enter"to run the code or Click in the cell belowandpress "Shift+Enter"to run the code and move to the next cell Menu: Cell... a.&g...原创 2020-01-05 10:08:20 · 158 阅读 · 0 评论 -
预测人格 项目 python 代码
#mian.pyfrom Enneagram_GUI import *from tkinter import *def center_window(root, width, height): screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() size ...原创 2019-12-31 08:01:19 · 2305 阅读 · 2 评论