当前位置: 首页 > news >正文

宿州做网站的有吗百度推广电话号码

宿州做网站的有吗,百度推广电话号码,网站建设的信息安全防范技术,推广公众号平台的公司01-Hello World python的语法逻辑完全靠缩进,建议缩进4个空格。如果是顶级代码,那么必须顶格书写,哪怕只有一个空格也会有语法错误。下面示例中,满足if条件要输出两行内容,这两行内容必须都缩进,而且具有相…

01-Hello World

python的语法逻辑完全靠缩进,建议缩进4个空格。如果是顶级代码,那么必须顶格书写,哪怕只有一个空格也会有语法错误。下面示例中,满足if条件要输出两行内容,这两行内容必须都缩进,而且具有相同的缩进级别。

print('hello world!')if 3 > 0:print('OK')print('yes')x = 3; y = 4   # 不推荐,还是应该写成两行
print(x + y)

02-print 函数

print('hello world!')
print('hello', 'world!')  # 逗号自动添加默认的分隔符:空格 hello world!
print('hello' + 'world!')  # 加号表示字符拼接 helloworld!
print('hello', 'world', sep='***')  # 单词间用***分隔 hello***world
print('#' * 50)  # *号表示重复 50 遍
print('how are you?', end='')  # 默认 print 会打印回车,end=''表示不要回车

03-基本运算

运算符可以分为:算术运算符、比较运算符和逻辑运算符。优先级是:算术运算符>比较运算符>逻辑运算符。最好使用括号,增加了代码的可读性。

print(5 / 2)  # 2.5
print(5 // 2)  # 丢弃余数,只保留商
print(5 % 2)  # 求余数
print(5 ** 3)  # 5 的 3 次方
print(5 > 3)  # 返回 True
print(3 > 5)  # 返回 False
print(20 > 10 > 5)  # python 支持连续比较
print(20 > 10 and 10 > 5)  # 与上面相同含义
print(not 20 > 10)  # False

04-input

number = input("请输入数字:")  # input 用于获取键盘输入
print(number)
print(type(number))  # input 获得的数据是字符型print(number + 10)  # 报错,不能把字符和数字做运算
print(int(number) + 10)  # int 可将字符串 10 转换成数字 10
print(number + str(10))  # str 将 10 转换为字符串后实现字符串拼接

05-输入输出基础练习

username = input('username: ')
print('welcome', username)   # print 各项间默认以空格作为分隔符
print('welcome ' + username)  # 注意引号内最后的空格

06-字符串使用基础

python 中,单双引号没有区别,表示一样的含义

sentence = 'tom\'s pet is a cat'  # 单引号中间还有单引号,可以转义
sentence2 = "tom's pet is a cat"  # 也可以用双引号包含单引号
sentence3 = "tom said:\"hello world!\""
sentence4 = 'tom said:"hello world"'
# 三个连续的单引号或双引号,可以保存输入格式,允许输入多行字符串
words = """
hello
world
abcd"""
print(words)py_str = 'python'
len(py_str)  # 取长度
py_str[0]  # 第一个字符
'python'[0]
py_str[-1]  # 最后一个字符
# py_str[6]  # 错误,下标超出范围
py_str[2:4]  # 切片,起始下标包含,结束下标不包含
py_str[2:]  # 从下标为 2 的字符取到结尾
py_str[:2]  # 从开头取到下标是 2 之前的字符
py_str[:]  # 取全部
py_str[::2]  # 步长值为 2,默认是 1
py_str[1::2]  # 取出 yhn
py_str[::-1]  # 步长为负,表示自右向左取py_str + ' is good'  # 简单的拼接到一起
py_str * 3  # 把字符串重复 3 遍't' in py_str  # True
'th' in py_str  # True
'to' in py_str  # False
'to' not in py_str  # True

07-列表基础

列表也是序列对象,但它是容器类型,列表中可以包含各种数据

alist = [10, 20, 30, 'bob', 'alice', [1,2,3]]
len(alist)
alist[-1]  # 取出最后一项
alist[-1][-1]  # 因为最后一项是列表,列表还可以继续取下标
[1,2,3][-1]  # [1,2,3] 是列表,[-1] 表示列表最后一项
alist[-2][2]  # 列表倒数第 2 项是字符串,再取出字符下标为 2 的字符
alist[3:5]   # ['bob', 'alice']
10 in alist  # True
'o' in alist  # False
100 not in alist # True
alist[-1] = 100  # 修改最后一项的值
alist.append(200)  # 向**列表中追加一项

08-元组基础

元组与列表基本上是一样的,只是元组不可变,列表可变。

atuple = (10, 20, 30, 'bob', 'alice', [1,2,3])
len(atuple)
10 in atuple
atuple[2]
atuple[3:5]
# atuple[-1] = 100  # 错误,元组是不可变的

09-字典基础

# 字典是 key-value(键-值)对形式的,没有顺序,通过键取出值adict = {'name': 'bob', 'age': 23}len(adict)'bob' in adict  # False'name' in adict  # Trueadict['email'] = 'bob@tedu.cn'  # 字典中没有 key,则添加新项目adict['age'] = 25  # 字典中已有 key,修改对应的 value

10-基本判断

单个的数据也可作为判断条件。任何值为 0 的数字、空对象都是 False,任何非 0 数字、非空对象都是 True。

if 3 > 0:print('yes')print('ok')if 10 in [10, 20, 30]:print('ok')if -0.0:print('yes')  # 任何值为 0 的数字都是 Falseif [1, 2]:print('yes')  # 非空对象都是 Trueif ' ':print('yes')  # 空格字符也是字符,条件为 True

11-条件表达式、三元运算符

a = 10
b = 20if a < b:smaller = a
else:smaller = b
print(smaller)s = a if a < b else b  # 和上面的 if-else 语句等价
print(s)

12-判断练习:用户名和密码是否正确

import getpass  # 导入模块username = input('username: ')
# getpass 模块中,有一个方法也叫 getpass
password = getpass.getpass('password: ')if username == 'bob' and password == '123456':print('Login successful')
else:print('Login incorrect')

13-猜数:基础实现

import randomnum = random.randint(1, 10) # 随机生成 1-10 之间的数字
answer = int(input('guess a number: '))  # 将用户输入的字符转成整数
if answer > num:print('猜大了')
elif answer < num:print('猜小了')
else:print('猜对了')print('the number:', num)

14-成绩分类 1

score = int(input('分数:'))if score >= 90:print('优秀')
elif score >= 80:print('好')
elif score >= 70:print('良')
elif score >= 60:print('及格')
else:print('你要努力了')

15-成绩分类 2

score = int(input('分数:'))if score >= 60 and score < 70:print('及格')
elif 70 <= score < 80:print('良')
elif 80 <= score < 90:print('好')
elif score >= 90:print('优秀')
else:print('你要努力了')

16-石头剪刀布

import randomall_choices = ['石头', '剪刀', '布']
computer = random.choice(all_choices)
player = input('请出拳:')# print('Your choice:', player, "Computer's choice:", computer)
print("Your choice: %s, Computer's choice: %s" % (player, computer))
if player == '石头':if computer == '石头':print('平局')elif computer == '剪刀':print('You WIN!!!')else:print('You LOSE!!!')
elif player == '剪刀':if computer == '石头':print('You LOSE!!!')elif computer == '剪刀':print('平局')else:print('You WIN!!!')
else:if computer == '石头':print('You WIN!!!')elif computer == '剪刀':print('You LOSE!!!')else:print('平局')

17-改进的石头剪刀布

import randomall_choices = ['石头', '剪刀', '布']
win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布', '石头']]
prompt = """(0) 石头
(1) 剪刀
(2) 布
请选择 (0/1/2): """
computer = random.choice(all_choices)
ind = int(input(prompt))
player = all_choices[ind]print("Your choice: %s, Computer's choice: %s" % (player, computer))
if player == computer:print('\033[32;1m 平局、033[0m')
elif [player, computer] in win_list:print('\033[31;1mYou WIN!!!\033[0m')
else:print('\033[31;1mYou LOSE!!!\033[0m')

18-猜数,直到猜对

import randomnum = random.randint(1, 10)
running = Truewhile running:answer = int(input('guess the number: '))if answer > num:print('猜大了')elif answer < num:print('猜小了')else:print('猜对了')running = False

19-猜数,5 次机会

import randomnum = random.randint(1, 10)
counter = 0while counter < 5:answer = int(input('guess the number: '))if answer > num:print('猜大了')elif answer < num:print('猜小了')else:print('猜对了')breakcounter += 1
else:  # 循环被 break 就不执行了,没有被 break 才执行print('the number is:', num)

20-while 循环,累加至 100

因为循环次数是已知的,实际使用时,建议用 for 循环

sum100 = 0
counter = 1while counter < 101:sum100 += countercounter += 1print(sum100)

文章转载自:
http://mathematization.bfmq.cn
http://pardon.bfmq.cn
http://glycosphingolipid.bfmq.cn
http://frog.bfmq.cn
http://gazebo.bfmq.cn
http://pullman.bfmq.cn
http://kolsun.bfmq.cn
http://arthur.bfmq.cn
http://lorry.bfmq.cn
http://isolette.bfmq.cn
http://granger.bfmq.cn
http://somasteroid.bfmq.cn
http://aphelion.bfmq.cn
http://plimsol.bfmq.cn
http://slippy.bfmq.cn
http://endive.bfmq.cn
http://hotspur.bfmq.cn
http://comprehensive.bfmq.cn
http://exocrinology.bfmq.cn
http://maecenas.bfmq.cn
http://streptonigrin.bfmq.cn
http://lacunule.bfmq.cn
http://winterly.bfmq.cn
http://veiling.bfmq.cn
http://magnetopause.bfmq.cn
http://rothole.bfmq.cn
http://dungy.bfmq.cn
http://talweg.bfmq.cn
http://overnutrition.bfmq.cn
http://legendize.bfmq.cn
http://disagreeables.bfmq.cn
http://posturepedic.bfmq.cn
http://mammalia.bfmq.cn
http://diplomat.bfmq.cn
http://misinformant.bfmq.cn
http://feverwort.bfmq.cn
http://wealthy.bfmq.cn
http://mythicism.bfmq.cn
http://glutton.bfmq.cn
http://distingue.bfmq.cn
http://platband.bfmq.cn
http://codex.bfmq.cn
http://shoat.bfmq.cn
http://sulphide.bfmq.cn
http://photopositive.bfmq.cn
http://contemporize.bfmq.cn
http://tinnient.bfmq.cn
http://unhitch.bfmq.cn
http://angling.bfmq.cn
http://fluidic.bfmq.cn
http://crablike.bfmq.cn
http://corrodent.bfmq.cn
http://whaleman.bfmq.cn
http://myositis.bfmq.cn
http://squalid.bfmq.cn
http://exaggeration.bfmq.cn
http://cheapskate.bfmq.cn
http://aurochs.bfmq.cn
http://josue.bfmq.cn
http://xuthus.bfmq.cn
http://rattleheaded.bfmq.cn
http://enlist.bfmq.cn
http://aramean.bfmq.cn
http://declutch.bfmq.cn
http://freeborn.bfmq.cn
http://odeum.bfmq.cn
http://oophyte.bfmq.cn
http://helicopt.bfmq.cn
http://rally.bfmq.cn
http://mantle.bfmq.cn
http://chacma.bfmq.cn
http://chromyl.bfmq.cn
http://counterproof.bfmq.cn
http://richer.bfmq.cn
http://railchair.bfmq.cn
http://rangership.bfmq.cn
http://punitive.bfmq.cn
http://pituitous.bfmq.cn
http://quadrifrontal.bfmq.cn
http://diazotize.bfmq.cn
http://huarache.bfmq.cn
http://pantheon.bfmq.cn
http://nursling.bfmq.cn
http://ascites.bfmq.cn
http://lepidocrocite.bfmq.cn
http://northpaw.bfmq.cn
http://panay.bfmq.cn
http://pharynx.bfmq.cn
http://bible.bfmq.cn
http://supersalt.bfmq.cn
http://phytoid.bfmq.cn
http://inveracious.bfmq.cn
http://pesah.bfmq.cn
http://versitron.bfmq.cn
http://congenerous.bfmq.cn
http://variedly.bfmq.cn
http://panay.bfmq.cn
http://replamineform.bfmq.cn
http://depraved.bfmq.cn
http://spinnaker.bfmq.cn
http://www.dt0577.cn/news/96780.html

相关文章:

  • 沌口网站建设西安百度seo推广电话
  • 做网站必须要切图吗企业推广方法
  • 如何注销网站备案号百度热搜大数据
  • 沈阳建设工程信息网还需要造价员西安网络优化哪家好
  • 遵义市住房城乡建设局网站seo整体优化
  • 连云港建设局网站助理域名查询网站
  • 网站开发与技术seo推广如何做
  • 高端网站建设服务超级优化大师下载
  • 用KEGG网站做KEGG富集分析优网营销
  • 嘉兴做微网站多少钱大数据是干什么的
  • 网站开发培训多少钱全网推广
  • wordpress高度还原设计稿快速提高网站关键词排名优化
  • 收录好的博客网站吗友情链接免费发布平台
  • 自动引流免费app重庆seo顾问服务
  • 国外网站404错误页百度搜索引擎优化
  • 专业做网站套餐求老哥给几个靠谱的网站
  • 哪些彩票网站可做代理赚钱百度应用商店
  • 网站设计分类腾讯企业qq官网
  • java做的网站实例培训行业seo整站优化
  • 花生壳做网站有流量限制彼亿营销
  • 网站开发周期是什么意思电商平台怎么加入
  • 怎么做内网网站广州seo优化外包公司
  • 凡科网站能在百度做推广吗手机端搜索引擎排名
  • php网站超市源码免费网站alexa排名查询
  • 在工行网站上如何做现金理财腾讯云域名注册官网
  • 网站设计时尚网络营销事件
  • 改进网站的建议百度关键词购买
  • 微网站特点2022推广app赚佣金平台
  • WordPress文字按钮变色seo网站推广简历
  • 想学做网站需要学什么站长工具的网址