计算机的初识

初识计算机。
CPU 内存,硬盘,操作系统 CPU:大脑,中央处理器,运算计算中心。 内存:缓冲硬盘和cpu,临时存储数据,供cpu运算。 优点:容量大,成本低,断电不消失。、 缺点:读取速度慢。 操作系统:调配,各个硬件的运行。 windows,linux,cenos,mac,。。。
硬盘:保存数据的  70MB/S
读写的内容都是01代码二进制
python发展史:1989年龟叔写出python语言
编程语言简单分类
最早的是机器语言
汇编语言
高级语言:C语言。Python,jave, c++, 

python发展史以影响。
python优点:优美,清晰,简单。
高级语言,开发效率高,可移植性
python缺点:速度慢,代码不能加密,线程不能利用多CPU问题 python分类:: python2x:源码不规范,源码混乱,重复代码较多。 python3x: 重整源码,源码规范,优美,清晰,简单。

4,语言的分类。 编译型: 将代码一次性全部编译成二进制,然后在运行。 优点:执行效率高。 缺点:开发效率慢,不能跨平台。 代表语言:C,C++,GO 解释型: 代码逐行解释,解释称二进制,然后运行。 优点:开发效率高,第三方库,可以跨平台。 缺点:执行效率低。 代表语言:python.java 5,Python的种类。 5.5运行第一个python文件: python 空格 文件路径,回车 python2x;默认的编码方式ascii 显示中文:首行: # -*- encoding: utf-8 -*-。 python3x: 默认的编码方式utf-8,。 python2x: print '内容' print('内容') python3x: print('内容') 6变量。 变量:将计算的中间结果存储起来,以便后续代码使用。
(程序运行过程中产生的值,临时保存在变量中,供后面的程序使用)
变量设定规则: 1,必须是字母,数字,下划线任意组合 2,不能是数字开头 3,不能是python中的关键字 ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield'] 4,变量不能是中文。 5,变量不能太长 6,变量有具有可描述性 驼峰体:简单首字母大写 AgeOfOldboy = 56 NumberOfStudents = 80 下划线:单词用下划线分开
age_of_oldboy
= 56 number_of_students = 80 常量:一直不变的量。在python中没有绝对的常量。默认全部大写的变量为常量。 身份证号,π, 注释。 帮助你理解别人代码,回忆自己的代码。 单行注释:# 多行注释 ''' 被注释内容''' """ 被注释内容""" 基础数据类型: 在python中么个变量都有类型的
int 数字,整数。用于计算。
+ - * / % // str ;字符串。在python中,凡是用引号引起来的就是字符串。
字符:你能看见的单一文字符号
空字符串:‘’ 空格:‘ ’ (都是字符串) print('这是字符串') print("这是字符串") msg = ''' 床前明月光, 疑是地上霜。 ''' 字符串:可加,可乘。 str + str :字符串的拼接。 print(msg) 相乘: str * int msg = '坚强' print(msg * 8) bool True False 两种状态:判定代码的真假。 print(3 > 2) print(3 > 4) print('True') print(True) 判断此对象是什么数据类型 type() print('True',type('True')) print(True,type(True)) 10,input用户输入11,if。 其他语言: if (条件){结果} if 条件: 结果 12,whilewhile
语法:
while 条件
代码块
说明:判断条件是否为真,如果真,执行代码块(循环体),执行完继续判断条件是否为真
如果真,继续执行,直到条件为假停止循环 终止循环: 1,改变条件。 2,break.(直接结束循环。) 关键字:break,打断循环,彻底停掉一个循环(停掉当前本次循环) continue,结束本次循环,继续下一次循环。
例子:break
count = 0
while count <= 100 : #只要count<=100就不断执行下面的代码
    print("loop ", count)
    if count == 5:
        break
    count +=1 #每执行一次,就把count+1,要不然就变成死循环啦,因为count一直是0

print("-----out of while loop ------")
View Code
例子:continue
count = 0
while count <= 100 : 
    count += 1
    if count > 5 and count < 95: #只要count在6-94之间,就不走下面的print语句,直接进入下一次loop
        continue 
    print("loop ", count)

print("-----out of while loop ------")
View Code

if 语句基本结构:
1,单独if
if 条件
  结果
print(111)
if 3 > 2:
    print(666)
print(333)
View Code
语法:
if 空格 条件:
    代码块
说明:当条件成立的时候(True),代码会被执行
View Code

2,if  else

if条件

else:

  结果

name = input('请输入你的名字:')
if name == '王爷':
    print('老铁,没毛病')
else:
    print('有病得治....')
View Code
语法:if 条件
                代码块
           else:
                 代码块
语法

3,if  elif...

num = int(input('请输入你得选择:'))  # str ---> int str全部由数字组成
if num == 4:
    print('中午饭我请')
elif num == 5:
    print('晚饭我请')
elif num == 6:
    print('麻辣烫‘,走起')
View Code
语法: if 条件1:
                    代码块1
           elif 条件2:
                   代码块2
           else:
当条件1成立,执行代码1 ,条件1不成立,再次判断条件2.。
只会执行其中的一个代码块
语法

4,if elif ... else

num = int(input('请输入你得选择:'))  # str ---> int str全部由数字组成
if num == 4:
    print('中午饭我请')
elif num == 5:
    print('晚饭我请')
elif num == 6:
    print('大保健,走起')
else:
    print('给你机会抓不住....')
View Code

5,嵌套:

num1 = input('请输入数字')
if num1 == '3':
    num2 = input('请输入数字:')
    if num2 == '5':
        print('这都能猜对')
    else:
        print('继续努力')

score = int(input("输入分数:"))
if score > 100:
    print("我擦,最高分才100...")
elif score >= 80:
    print("B")
elif score >= 90:
    print("A")
elif score >= 60:
    print("C")
elif score >= 40:
    print("D")
else:
    print("太笨了...E")
View Code

while循环语句:

while True:
    print('精忠报国')
    print('粉红的回忆')
    print('凉凉')
    print('起风了')
View Code
flag = True
while flag:
    print('精忠报国')
    print('粉红的回忆')
    print('凉凉')
    flag = False
    print('第一次'
View Code

while循环(1-100)

count = 1
while count < 101:
    print(count)
    count = count + 1 # count += 1
View Code
方法一:
count = 0
while count < 101:
    print(count)
    count = count + 2
方法二:
count = 0
while count < 101:
    if count % 2 == 0:
        print(count)
    count = count + 1
while循环(0-100)取偶数
count = 1
sum = 0
while True:
    sum = sum + count
    count = count + 1
    if count == 101:break
print(sum)
brea while计算1+2+...+100
 
原文地址:https://www.cnblogs.com/ls13691357174/p/9093167.html