Python入门(一)数据类型、循环语句

脚本语言类型:

1.编译型语言:写完代码不能执行,需要先编译     eg:c、c++、c#

2.解释性语言:不需要编译 直接执行                      eg:python、java、php、js、go、ruby

 

编程工具  pycharm

1.破解方法:https://blog.csdn.net/sophia_11/article/details/86520390   ; idea.lanyus.com

2.创建 New project

create new project -》pure python  (选择路径)-》new-》python file

注:选择existing interpreter 避免创建虚拟环境

 

3.修改python版本:

                  

 

Python 数据类型

1.定义变量:  变量名 = ‘变量值’

2.整数  int:Python可以处理任意大小的整数,当然包括负整数,在Python程序中,整数的表示方法和数学上的写法一模一样,例如:1100-80800,等等。

3.浮点数  float:浮点数也就是小数,之所以称为浮点数,是因为按照科学记数法表示时,一个浮点数的小数点位置是可变的,比如,1.23x10^9和12.3x10^8是相等的。

4.字符串  string:字符串是以''""括起来的任意文本,比如'abc',"xyz"等等。

5.布尔值:布尔值和布尔代数的表示完全一致,一个布尔值只有TrueFalse两种值,要么是True,要么是False,在Python中,可以直接用TrueFalse表示布尔值(请注意大小写),也可以通过布尔运算计算出来。

6.空值  None:空值是Python里一个特殊的值,用None表示。

 

Python print语句

1.print语句:eg:print ('hello,word')

注:python3 强制使用('hello,word')格式,python2可以使用'hello,word'格式

2.特殊语句: print ('''  let's go "a b"  ''')

 

Python 注释方法

1.单行注释:#print ('hello,word')

2.批量注释:'''         '''  或者  """    """

 

Python  input用法

 1.input 语句: name = input ("请输入用户名).strip()      <-去除空格

 

 

Python条件判断和循环

 

1.if条件判断:(相等==,不相等!=,大于等于>=,小于等于<=)

age = 20
if age >= 18:
    print 'your age is', age
    print 'adult'
print 'END'

2.if .. else

if age >= 18:
    print 'adult'
else:
    print 'teenager'

3. if .. elif ..else
if age >= 18:
    print 'adult'
elif age >= 6:
    print 'teenager'
elif age >= 3:
    print 'kid'
else:
    print 'baby'

4.for 循环
L = ['Adam', 'Lisa', 'Bart']
for name in L:
    print name

5.while循环
N = 10
x = 0
while x < N:
    print x
    x = x + 1

6.break退出
sum = 0
x = 1
while True:
    sum = sum + x
    x = x + 1
    if x > 100:
        break
print sum

7.continue继续
L = [75, 98, 59, 81, 66, 43, 69, 85]
sum = 0.0
n = 0
for x in L:
    if x < 60:
        continue
    sum = sum + x
    n = n + 1





posted @ 2019-03-29 14:32  辰毒秀  阅读(206)  评论(0编辑  收藏  举报