随笔分类 - python
摘要:Python中的 if __name__ == '__main__' 是什么意思? 对于Python初学者,在看到这个if __name__ == '__main__' 的判断,并且下面还有代码语句,看了其他地方的说明,还是没搞明白是什么意思, 在看到这句话时,终于醍醐灌顶,就是下面这句话: __n
阅读全文
摘要:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n]
阅读全文
摘要:给定一个列表,然后给一个目标值,列表中两数求和等于目标值,要求输出列表两数的下界 如 list = [1,2,3,4,6,7,8] num=10 #!/usr/bin/python #coding=utf-8 list = [1,2,3,4,6,7,8] num=10 for m in range(
阅读全文
摘要:#/usr/bin/python #coding=utf-8 class Car(): def __init__(self,name,year): self.name = name self.year = year def model(self): vv = f"my car is {self.na
阅读全文
摘要:原因:pip源超时了,安装不上 pip install matplotlib -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技
阅读全文
摘要:#!/usr/bin/python # -*- coding: UTF-8 -*- import json numbers = [2,3,4,7,11,13] filename = 'numbers.json' with open(filename,'w') as f: json.dump(numb
阅读全文
摘要:使用 try-except代码块来处理异常。
阅读全文
摘要:人生苦短,我用Python 博客园精华区01-15 23:46 (一)认识Python Python背景介绍 Python的格言: Life is short,use python. (人生苦短,我用Python。) 由Guido van Rossum于1989年圣诞节为打发无聊时间,而开发的一个新
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 lst = ['hongkong','xiantyk','chinat','guangdong','z'] lst2 = [] lst3 = [] lst4 = [] def get_num(): for i in
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 class Car: """一次模拟汽车的简单尝试""" def __init__(self,make,model,year): """初始化汽车的属性""" self.make = make self.model
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 class Dog: """一次模拟小狗的简单尝试""" def __init__(self,name,age): """初始化属性名字和年龄""" self.name = name self.age = age
阅读全文
摘要:导入整个模块: import 模块名 导入特定函数: from module_name import function_name 通过逗号可以分割函数名,如果需要导入多个则 from a import b,c,d,e View Code
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 def make_pizza(*toppings): print("\nmaking a pizza with the following toppings:") for topping in toppings:
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 def describe_pet(type,name): print(f"i have a {type};") print(f"my {type}'s name is {name}!") describe_pet(
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 def describe_pet(type,name): print(f"i have a {type};") print(f"my {type}'s name is {name}!") describe_pet(
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 def user(username): """显示用户名""" print(f"hello,{username.title()}!") user("tiger")
阅读全文
摘要:#!/usr/bin/python #coding=utf-8 #好好学习,天天向上 a = 1 while a <= 6: print(a) a = a + 1 #!/usr/bin/python #coding=utf-8 #好好学习,天天向上 a = 1 while a <= 6: a = a
阅读全文