莫烦Python-笔记

一、B站-《莫烦python》

(一)、安装python

1.安装网址:官网-Welcome to Python.org-download-下载即可

2.下载完成后,右键选以管理员身份运行,不断点击默认即可下载成功。

(二)Print()函数

#打印数字
print(123)                #输出:123
print(1+2)                #输出:3
print(int('1')+2)        #输出:3
print('1+2')                #输出:1+2  ''中的是字符
print(float('1.2')+2)        #输出:3.2  浮点数要用float()
#打印一句话:str类型(字符串)
print("we're going to do sth")        #要使用英文状态下的单引号或双引号来引用
print('we')
#但如想打印出:I'm zsc str中有'时可:
print("I'm zsc")                    #使用双引号,避免把字符串中的引号认为是字符串的结束
print('I\'m zsc')                    #使用转义字符\在但单引号前,告知系统此符号是内容
#实现拼接
print('apple'+'car')
print('apple'+'4')                #'':4这个字符
print('apple'+str(4))               #str(4),将int型强制转换为str类型
print(float('1.2')+1.2)               #单引号把小数1.2转换为了str类型,float又转回

(三)数学

#python中数学可直接计算
1+1                    #2(加法)
1-1                    #0(减法)
2*2                    #4(乘法)
#计算平方时要用**表示几次方
2**2                    #4(平方)
2**3                    #8(三次方)
#取余数——取模要用%
8%2                    #0(能整除,余0)
8%3                    #2(除3,余2)
#取整——要用符号//
9//4                    #2(相除后商是2)
9//3                    #3(相除后商是3)
9//2                    #4(相除后商是4)

(四)自变量variable

        我们可能需要把数值或者运算存储在一个内存当中来继续后续的运算——自变量

apple=1
print(apple)                    #输出1
#命名形式:apple_egg、apple_EGG、appleEgg
#自变量也可以是一个运算
appleEgg = 12 + 3
print(appleEgg)                #输出15
#一次定义多个自变量
a=1
b=2
c=3
print(a,b,c)                    #输出1 2 3
d,e,f=4,5,6
print(d,e,f)                    #输出 4 5 6
#自变量在存储运算时也可以含有自变量
a=1
b=a*2
print(a,b)                    #输出1 2

(五)while循环

        当满足某种情况时,就运行代码

condition = 1
while condition <10:
    print(condition)
    condition = condition + 1

        True表示正确、对,False表示错误。当while中判断是正确时,就运行代码,错误就跳出代码。例如上述condition从1开始到9都是小于10,即正确的,就运行代码。

while True:
    print("I'm True")        #就会不断循环打印,不会跳出循环

(六)for循环

        相当于给定一个区间,相当于一个迭代器的作用。

example_list=[2,1,9,6,3,7,8,5,456,82]
for i in example_list:
    print(i)                        #把example_list中的每个都打印出来
print('outer of for')                #注意缩进和循环

        python中有一个内部的函数:range-自动的迭代器

        range的参数:range(开始,停止,步长)

        步长不一定要写

for i in range(1,10):
    print(i)                #含头不含尾,输出的是:1 2 3 4 5 6 7 8 9      
for i in range(1,10,2):
    print(i)                  #输出1 3 5 7 9
for i in range(1,10,5):
    print(i)                  #输出1 6

(七)if条件判断语句

x=1
y=2
z=3

if x>y:
    print("x is greater than y")                #判断条件结果是false,不输出
if x<y:
    print("x is less than y")                   #判断条件结果是true,输出: x is less than y
if x<y<z:
    print("x is less than y,and y less than z") 
#判断条件结果是true,输出: x is less than y,and y less than z
if x<=y:
    print("x is less or equal than y")                   
#判断条件结果是true,输出: x is less or equal than y

        判断是否相等时,不能用等号=,python中等号是赋值的意思,若想判断是否相等时,要使用双等号==。若不相等时,运行代码使用:  !=     意思是不相等。

不想做笔记了,只看视频,没后续了(/(ㄒoㄒ)/~~)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值