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

本文介绍Python的基础概念,包括数据类型如整数、浮点数、字符串、布尔值及空值None,同时讲解了print语句的使用方法,注释的写法,input函数的应用,并提供了条件判断与循环的基本语法。

脚本语言类型:

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

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

 

编程工具  pycharm

1.破解方法:https://blog.youkuaiyun.com/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




转载于:https://www.cnblogs.com/chenduxiu/p/10621089.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值