2018-09-19

1,安装Python

https://www.python.org下载python安装包,点击执行安装

2,使用IDLE

1)打开IDLE,选择“File”-“New File”新建一个文件
2)输入如下代码

print('Hello,python!')

3)选择“File”-“Save”,输入文件名“hello”保存文件
4)选择“Run”-“Run Module”运行文件,查看输出结果如下

Hello,python!

3,变量

1)命名

字母、数字、下划线

2)赋值

=,input

name='wangzixi'
name=input('What's your name?  ')

4,数字

整数int: 0,1,10,99999,-1,-50
浮点数float:3.14,0.05,-23.4567

5,运算符号

加:+
减:-
乘:*
除:/
括号:()

6,字符串str

'wangzixi',"wangziyi","What's your name?"

7,列表 []

family=['dad','mom','xixi','yiyi']

8,for循环

for x in range(10):
  print(x)

total=0
for i in range(1,101):
  total=total+i
print(total)

family=['dad','mom','xixi','yiyi']
for person in family:
  print(person)

9,注释

#这是单行注释
print('Hello')  #print('Hello, single line comment')
/*
这是多行注释
我是新的一行
print('Hello, multiple lines comment')
*/

10,布尔bool

真:True
假:False

x=5
x>4
x>6

11,逻辑运算

与(而且、并且):and
或(或者):or
非(取反):not

x=5
x>4 and x >3
x>4 and x> 6
x>4 or x>3
x>4 or x>6

x>6
not x>6

12,比较

大于:>
小于:<
等于:==
大于等于:>=
小于等于:<=
不等于:!=

x=5
x>4
x>=5
x<3
x<=10
x==6
x!=7

s1='hello'
s2=='world'
s='hello'
s1==s2
s1==s

13,while循环

i=1
total=0
while i<=100:
  total=total+i
  i=i+1
print(total)

14,条件判断

if

age=eval(input('How old are you? '))
if age>=6:  #如果
  print('You can go to school.')

if ...else...

age=eval(input('How old are you? '))
if age>=6:  #如果
  print('You can go to school.')
else: #那么、否则
  print('You can't go to school.')

if...elif...else

age=eval(input('How old are you? '))
if age>=6:  #如果
  print('You can go to school.')
elif age>=3: #否则如果
  print('You can go to youeryuan.')
else:#否则
  print('You can't go to any school.')
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 5,848评论 0 10
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,079评论 19 139
  • 人们极其容易被极其安静的人蒙骗,人们往往默认安静的人就不会使坏,但安静背后藏着的是一个大好人还是大混蛋,谁知道呢?...
    五毫子硬币阅读 293评论 0 0
  • 酸甜特好吃 ,肉多汁多皮薄!
    侬_碧华水果阅读 383评论 0 0
  • 使用lsof命令查询占用端口的进程PID: lsof -i:8888 若要关闭使用这个端口的程序,使用kill +...
    徐子鑑阅读 507评论 0 0