# coding=UTF-8

# 字体编码,coding必须在第一行

# 01

print("Hello World")

# 02

score = 77

if score >= 80:

print(score)

else:

print("分数过低")

# 03

# rang(1,6), 不包含6

# for i in range(1, 6):

# print(i ** 2)

# 04

# while True:

# i = input("请输入内容:")

# if i == "stop":

# break

# elif not i.isdigit():

# if i.isspace():

# print("不能输入空格")

# else:

# print("请输入数字")

#

# else:

# j = int(i)

# if j > 20:

# print("输入的数字太大了")

# elif j < 10:

# print("输入的数字太小了")

# else:

# print("输入正确")

# 05 循环增加

# i = 1

# while True:

# if i >= 10:

# print("大于10,退出")

# break

# else:

# i = i + 1

# print(i)

# print("+1中...")

# 06 默认浏览器打开网页

# url = "https://www.baidu.com/"

# import webbrowser

#

# webbrowser.open(url)

# True

# 07 读取网页内容 python 2+版本

# import urllib2

#

# html = urllib2.urlopen(url)

# print(html.read())

# 08 访问网页

url = "https://blog.csdn.net/qq_33160790"

# import urllib.request

#

# req = urllib.request.Request(url)

# reqs = urllib.request.urlopen(req)

# data = reqs.read().decode("utf-8")

# print(data)

# 09 单独获取url,暂未成功

# from lxml import etree

# import requests

#

# req = requests.get(url)

# if req.status_code == requests.codes.ok:

# html = etree.HTML(req.text)

# hrefs = html.xpath('span[@class="link_title"]/a/@href')

# for href in hrefs:

# print(href)

result = False

if result:

print("true")

else:

print("false false")

# 10 多行注释

'''

这是多行注释,使用单引号。

这是多行注释,使用单引号。

这是多行注释,使用单引号。

'''

# 11 单行显示

x = "1"

y = "2"

print(x, y)

# 12 多变量赋值

a = b = c = 1

print(a, b, c)

a, b, c = 1, 2, "雄"

print(a, b, c)

# 13 list 列表

# 0 1 2 3 4 5 6 7 8

# 列表

list = ["a", "b", "c", "d", "e", 1, 2, 2, 2]

# 数组

tuple = ("1", "2", "3", "4", "a", "b")

# 包含1, 不包含3

print(list[1:3])

print(tuple[1:3])

print(list[2:])

print(tuple[2:])

# 2出现的次数

print(list.count(2))

print(tuple.count("2"))

# position=2

print(list[2])

print(tuple[2])

# 14 字典

tinydict = {'name': 'john', 'code': 6734, 'dept': 'sales'}

print("key=", tinydict.keys())

print("value=", tinydict.values())

print(tinydict.copy())

# 15 强转

x = 1

y = 1.0

print(float(x))

print(int(y))

# 16 判断值是否被包含在内

if x in tinydict:

print(True)

else:

print(False)

if "code" in tinydict:

print(True)

else:

print(False)

# 17 身份运算符

a = 10

b = 10

if a is b:

print(True)

else:

print(False)

# 18 循环 break与 continue区别

for tiny in tinydict:

print(tiny)

print("结束")

for letter in "python":

if letter == "h":

# 1 终止当前循环

# break

# 2 跳过当前值, 继续下一轮

continue

else:

print(letter)

# 19 while 循环

# 倒叙, 从16开始判断

numbers = [11, 12, 13, 14, 15, 16]

even = []

odd = []

while len(numbers) > 0:

number = numbers.pop()

if number % 2 == 0:

# 附加

even.append(number)

else:

odd.append(number)

print("偶数", even)

print("基数", odd)

numbers1 = [11, 12, 13, 14, 15, 16]

# [-2] 读取列表中倒数第二个元素

print("-2的位置=", numbers1[-2]) # 15

print("最大值=", max(numbers1))

del numbers1[2]

print("删除一个元素后:", numbers1)

# 20 math 方法

import math

i = math.pow(2, 3) # 2的3次方

print(i)

# 21 替换带有%s的符号

print("My name is %s and weight is %s kg! I'm %s" % ('Zara', 21, "beautiful"))

# 22 时间戳 年月日 时分秒

import time

print("当前时间为=", time.asctime(time.localtime(time.time())))

print("时间为:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

# 23 打印日历

import calendar

cal = calendar.month(2018, 9)

print(cal)

import datetime

now = datetime.datetime.now()

print("现在的时间是:", now)

# 24 方法

def enter(str, str2):

print(str, str2)

return

enter("我要调用enter方法", "参数2")

enter(1, "参数22")

# 25 lambda

# 后面的x-y才是运算式

sum = lambda x, y, z: x - y + z;

print("lambda相加=", sum(10, 20, 11))

print("lambda相加=", sum(20, 30, 12))

money = 100

def addMoney():

global money

money = money + 1

print(money)

addMoney()

print(money)

# content = dir(math)

# print(content)

# 异常捕获

try:

file1 = open("refile.txt", "w")

file1.write("我是测试数据")

except IOError:

print("写入异常")

else:

print("写入成功")

file1.closed

一键复制

编辑

Web IDE

原始数据

按行查看

历史

python demo.py_pythonDemo.py相关推荐

  1. python中main.py是什么意思_关于python:什么是__main__.py?

    __main__.py文件是用来做什么的,我应该把什么类型的代码放进去,什么时候应该有一个? 通常,通过在命令行中命名.py文件来运行python程序: $ python my_program.py ...

  2. Dobot机械臂的Python Demo

    官网下载地址:[OFFICIAL]Dobot Magician Download Center | DOBOT 0.Python Demo流程: 一.下载安装python 3.7.5 64-bit 二 ...

  3. [Python] cmd中‘py‘命令不被识别的解决方案

    [Python] cmd中'py'命令不被识别的解决方案 附:环境变量设置方法 最近我的兴趣从Python转移到了C语言,在给MinGW-W64添加环境变量(Path)的时候,不小心覆写了Python ...

  4. 成功解决python\ops\seq2seq.py TypeError: ms_error() got an unexpected keyword argument 'logits'

    成功解决python\ops\seq2seq.py  TypeError: ms_error() got an unexpected keyword argument 'logits' 目录 解决问题 ...

  5. 成功解决python\ops\seq2seq.py TypeError: ms_error() got an unexpected keyword argument 'labels'

    成功解决python\ops\seq2seq.py TypeError: ms_error() got an unexpected keyword argument 'labels' 目录 解决问题 ...

  6. python的setup.py文件及其常用命令

    python的setup.py文件及其常用命令 上传者:tingting1718      我也要"分享赚钱" 2014/7/7 关注(286) 评论(0) 声明:此内容仅代表网友 ...

  7. 第一个Python程序hello.py提示出现File stdin,line 1错误

    写第一个Python程序hello.py,内容仅有一句,print 'hello world', 运行 Python hello.py 出错,提示: File "<stdin>& ...

  8. envs\TensorFlow2.0\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning 解决方案

    import tensorflow后的完整报错: D:\Anaconda3\envs\TensorFlow2.0\lib\site-packages\tensorflow\python\framewo ...

  9. 用python配置文件_使用。Python中的Py配置文件,python

    python中使用.py配置文件 一.格式: ​ 创建一个config.py文件 ​ 在文件中加配置: DEBUG=True dm_connect = { "dm_host":&q ...

最新文章

  1. 2021年大数据Spark(三十五):SparkStreaming数据抽象 DStream
  2. C++中try/catch/throw的使用
  3. Jupyter官方神器:可视化 Debug 工具!
  4. 用python实现结构体数组
  5. 操作系统设计与实现第3版笔记与minix3心得(5)-操作系统发展历史(3)
  6. python中用于绘制各种图形、标注文本_python ImageDraw类实现几何图形的绘制与文字的绘制...
  7. 使用JNDI操作LDAP(4)(转载)
  8. 操作系统习题——(习题二)
  9. 为旗下硬件产品服务,LG推出基于SLAM技术的3D摄像头
  10. 程序员面试金典 - 面试题 05.04. 下一个数(线性扫描)
  11. 情侣签到365天获1000现金?这款App被关停下架了 网友拍手称快!
  12. icmp协议_CCNA - Part7:网络层 - ICMP 应该是你最熟悉的协议了
  13. KMP算法 AC自动机
  14. 手把手教你把Python代码转成exe
  15. html 表格输出excel,html中导出excel表格
  16. 【端午安康SXY】Python正则表达式进阶用法(以批量修改Markdown英文字体为例)
  17. 笔记33 笨办法学python练习40之二:类和对象
  18. vs2019 C#提示程序未兼容
  19. 替代变量与SQL*Plus环境设置 (转自一沙弥的世界)
  20. SQL研习录(24)——CHECK约束

热门文章

  1. jdk9、jdk10、jdk11、jdk12、jdk13新特性
  2. 如何优雅的使用 win10
  3. 一个疯子的梦-20190921
  4. 《Saladict》谷歌!有道!我全都要! 聚合词典, 并行翻译
  5. 什么是OAuth2,微信登录前后端实现,Coding在线(十三)
  6. 自考计算机网络技术04741
  7. c语言上机实验作业答案,C语言上机实验-答案
  8. 冷链食品追溯迫在眉睫,爱码物联3步助力冷链溯源
  9. c++中的友元和组合
  10. 10分钟教你如何自动化操控浏览器——Selenium测试工具